带有长文本的Textfield,水平滚动重置要开始 - 扑响
构建一个具有特定宽度容器内文本字段的状态小部件。现在,当我在Textfield中键入长文本时,视图滚动在您键入时正确(按预期工作)。但是,当我在Textfield外面点击时,我已经不关注Textfield。当我取消关注时,如何将Textfield的视图重置回文本的开头? IE将水平滚动移回开始?
这是Textfield小部件,
textContainer = Container(
width: MediaQuery.of(context).size.width * 0.68,
child: Focus(
child: TextField(
keyboardType: TextInputType.text,
textCapitalization: TextCapitalization.sentences,
onSubmitted: onSubmit,
controller: textController,
focusNode: widget.focusNode,
maxLines: 1,
autofocus: widget.isNew,
cursorColor: Colors.white,
style: const TextStyle(
fontSize: 16.0,
fontFamily: 'Inter',
fontWeight: FontWeight.normal,
color: Colors.white
),
decoration: const InputDecoration(
border: InputBorder.none,
),
onChanged: (text) {
Task task = taskBox.get(widget.task.id);
task.text = text;
taskBox.put(widget.task.id, task);
},
),
onFocusChange: (hasFocus) {
showDeleteBtn(hasFocus);
},
)
);
请参阅GIF的中部,当我解开TextField时,我想将视图/滚动返回到小部件的开头。尝试重建小部件,但行不通。
Building a stateful widget with a textfield wrapped within a Container of specific width. Now, when I type a long text in the textfield, the view scrolls right as you type (works as expected). But when I tap outside of the textfield, I've unfocused the textField. When I unfocus, how do I programatically reset the view of the textfield back to the beginning of the text? i.e. Move the horizontal scroll back to the beginning?
Here's the textField widget
textContainer = Container(
width: MediaQuery.of(context).size.width * 0.68,
child: Focus(
child: TextField(
keyboardType: TextInputType.text,
textCapitalization: TextCapitalization.sentences,
onSubmitted: onSubmit,
controller: textController,
focusNode: widget.focusNode,
maxLines: 1,
autofocus: widget.isNew,
cursorColor: Colors.white,
style: const TextStyle(
fontSize: 16.0,
fontFamily: 'Inter',
fontWeight: FontWeight.normal,
color: Colors.white
),
decoration: const InputDecoration(
border: InputBorder.none,
),
onChanged: (text) {
Task task = taskBox.get(widget.task.id);
task.text = text;
taskBox.put(widget.task.id, task);
},
),
onFocusChange: (hasFocus) {
showDeleteBtn(hasFocus);
},
)
);
See the mid part of the gif, when I unfocus the textfield, I'd like to push the view/scroll back to the beginning of the widget. Tried rebuild the widget, but doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
scrollController
内部textfield
,而在textfiled get de not de not cops in start开始。You can use
ScrollController
insideTextField
and while textfiled get unfocused jump to start.