使用 RTL 语言编辑文本时 Flutter 中的错误

AVE*_*imi 2 android right-to-left flutter flutter-widget text-direction

Flutter 在使用 RTL(从右到左)TextField 时存在错误。如果我们点击(A),光标将停在B处,即文本末尾的前一个,并且我们无法编辑最后一个字符!我创建了这个问题,希望 Flutter 人们能够看到它并修复它

在此输入图像描述

Nav*_*ini 5

我解决了这个错误..

在您的 TextField 中,您应该使用控制器和 onTab 函数编写

if (textController.selection ==
                            TextSelection.fromPosition(TextPosition(
                                offset:
                                    textController.text.length -
                                        1))) {
                          textController.selection =
                              TextSelection.fromPosition(TextPosition(
                                  offset: textController.text.length));
                        }
Run Code Online (Sandbox Code Playgroud)

完整的例子就像

   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) {  },
             );
Run Code Online (Sandbox Code Playgroud)