如何在文本字段中flutter的值的末尾设置光标位置? [英] how to set cursor position at the end of the value in flutter in textfield?

查看:456
本文介绍了如何在文本字段中flutter的值的末尾设置光标位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是我想在文本字段的值末尾添加,00",在iOS设备中效果很好,但是在android中,光标移动到文本字段中值的起点.因此,我无法添加,00".

the problem is i want to add ",00" at the end of the value of the textfield works good in iOS device but in android cursor moves to starting point of the value in textfield. So, i'm unable to add ",00".

推荐答案

我在设置TextEditingController时遇到了同样的问题,这对我有用.

I've been having the same problem with setting a TextEditingController and this is what worked for me.

controller.text = someString;
controller.selection = TextSelection.fromPosition(TextPosition(offset: controller.text.length));

TextSelection.fromPosition()(从文档中)执行以下操作:

TextSelection.fromPosition() does the following (from the documentation):

在给定的文本位置创建一个折叠的选择.崩溃了 选择以相同的偏移量开始和结束,这意味着它包含 零个字符,但用作文本中的插入点.

Creates a collapsed selection at the given text position. A collapsed selection starts and ends at the same offset, which means it contains zero characters but instead serves as an insertion point in the text.

这篇关于如何在文本字段中flutter的值的末尾设置光标位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆