Flutter TextEditingController无法在键盘上方滚动 [英] Flutter TextEditingController does not scroll above keyboard

查看:234
本文介绍了Flutter TextEditingController无法在键盘上方滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在android版本中,Flutter TextEditingController不会像在开始输入字段时默认文本字段那样在键盘上方滚动.我试图查看flutter示例目录中提供的示例应用程序,但即使没有TextEditController此类行为的示例.

In android version, Flutter TextEditingController does not scroll above keyboard like default text fields do when you start typing in field. I tried to look in sample apps provided in flutter example directory, but even there are no example of TextEditController with such behaviour.

有什么方法可以实现吗?

Is there any way to implement this.

谢谢.

推荐答案

感谢大家提供了指向正确方向的有用的答案@ user2785693.
我在这里找到了完整的工作解决方案:

Thank you all for the helpful answers @user2785693 pointed in the right direction.
I found complete working solution here: here

仅使用scroll或focusNode.listner的问题是,仅当我第一次关注文本框时它才起作用,但是如果我最小化键盘并再次单击已经具有焦点的同一个文本框,则listner回调为未触发,因此自动滚动代码未运行.解决方案是在状态类中添加"WidgetsBindingObserver",并覆盖"didChangeMetrics"功能.

Issue with just using scroll or focusNode.listner is, it was working only if I focus on textbox for the first time, but if I minimize the keyboard and again click on same text box which already had focus, the listner callback was not firing, so the auto scroll code was not running. Solution was to add "WidgetsBindingObserver" to state class and override "didChangeMetrics" function.

希望这可以帮助其他人使Flutter表单更加用户友好.

Hope this helps others to make Flutter forms more user friendly.

这篇关于Flutter TextEditingController无法在键盘上方滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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