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

标签 android flutter right-to-left flutter-widget text-direction

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

enter image description here

最佳答案

我解决了这个错误..

在您的 TextField 中,您应该使用 Controller 和 onTab 函数写入

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

完整示例,例如

   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) {  },
             );

关于android - 使用 RTL 语言编辑文本时 Flutter 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72726230/

相关文章:

android - 无法降级 Android 最低 sdk

flutter - 通过MaterialPageRoute进行路由时,Flutter Page的数据未加载,但是热重加载是否正确加载了数据?

flutter - 如何使文本自动调整大小?

android - 为什么用c源代码调试时GDB是 "jumping back"

java - 代码中未经检查的强制转换警告

android - RTL 支持 : Disabling it only for specific UI components

html - 以从右到左的语言从左到右显示电话号码

java - 键盘 View 键码不起作用

flutter - 如何在 flutter 中的两个按钮之间留出空间?