Flutter TextField输入框光标位置问题

键盘成为第一响应者,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,
                ),
              ),
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容