如何在TextFormField(最好使用TextedingController)中获得当前的光标位置?
我正在尝试实现类似于Instagram的“注释用户”功能。
要求:
- 当用户在“@”之后键入一个或多个字符时,应显示用户列表。
- 要查询的术语可以在文本中的任何地方,而不仅仅是最后。
- 可以有多个标记的用户。
找到 this flutter中用户tagging的答案,但是仅当标签在文本的末尾时,它才显示一个建议列表。打字。如果我可以根据textformfield
中的当前光标位置修改此行为,那将是很棒的。我查看了textedingcontroller
api,以找到类似的东西,但找不到任何有用的东西。
有什么方法可以获取此类信息,还是我缺少一些东西?
I am trying to implement the 'Tagging users in comments' feature similar to Instagram.
Requirements:
- A list of users should be shown when a user types one or more characters after '@'.
- The term to be queried can be anywhere in the text and not just at the end.
- There can be more than one tagged user.
Found this answer for user-tagging in Flutter, but it shows a suggestion list only if the tag is at the end of the text while typing. It would be great if I could modify this behavior based on the current cursor position in the TextFormField
. I looked at the TextEditingController
API to find something similar but could not find anything useful.
Is there any way to get such information or am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的要求:
@
之后显示用户列表,则可能必须创建一个可以在用户列表中显示为弹出窗口的小部件。为此,您可以检查其他有用的软件包: https://pub.dev/packages? a>
注意:由于您尚未提供任何代码,我无法提供适当的解决方案,但是所有链接都会有助于获取您的解决方案。
As per your requirements:
@
, You may have to create a Widget that can show as a popup with the list of users. For that, you can check https://stackoverflow.com/a/57846261/1318946Other useful packages: https://pub.dev/packages?q=mention
Note: As you haven't provided any code, I can't give a proper solution, but all the links will be helpful to get your solution.