AVEbrahimi
AVEbrahimi

Reputation: 19214

Bug in Flutter, while editing text in RTL languages

There is a bug in Flutter while using RTL (Right To Left) TextField. If we click on (A), the cursor will stop at B, one before the end of the text, and we can't edit the last character! I created this issue and I hope Flutter people see it and fix it

enter image description here

Upvotes: 2

Views: 751

Answers (1)

Navid Hosseini
Navid Hosseini

Reputation: 144

I solve this bug ..

in your TextField you should use controller and onTab function write

if (textController.selection ==
                            TextSelection.fromPosition(TextPosition(
                                offset:
                                    textController.text.length -
                                        1))) {
                          textController.selection =
                              TextSelection.fromPosition(TextPosition(
                                  offset: textController.text.length));
                        }

full example like

   TextField(
                      textAlign: TextAlign.right,
                      textDirection: TextDirection.rtl,
                      controller:textController,
                      maxLength: 10,
                      onTap: () {
                        if (textController.selection ==
                            TextSelection.fromPosition(TextPosition(
                                offset:
                                    textController.text.length -
                                        1))) {
                          textController.selection =
                              TextSelection.fromPosition(TextPosition(
                                  offset:textController.text.length));
                        }
                      },
                      onChanged: (text) {  },
             );

Upvotes: 5

Related Questions