美文网首页
Flutter TextField输入框光标位置问题

Flutter TextField输入框光标位置问题

作者: 北纬357 | 来源:发表于2021-02-20 11:45 被阅读0次
键盘成为第一响应者,TextField有默认文字时,光标没有位于最后的位置
              Expanded(
                child: CupertinoTextField(
                  controller: TextEditingController.fromValue(TextEditingValue(
                      text: defaultText,
                      // 保持光标在最后
                      selection: TextSelection.fromPosition(TextPosition(
                          affinity: TextAffinity.downstream,
                          offset: defaultText.length)))),
                  decoration: BoxDecoration(
                    color: Colors.grey.shade50,
                    border: Border.all(color: Colors.grey, width: 0.3),
                    borderRadius: BorderRadius.all(Radius.circular(5)),
                  ),
                  onChanged: (text) {
                    newGroupName = text;
                  },
                  autofocus: true,
                  cursorColor: Colors.green,
                ),
              ),

相关文章

网友评论

      本文标题:Flutter TextField输入框光标位置问题

      本文链接:https://www.haomeiwen.com/subject/urmtfltx.html