在安卓版本中,Flutter不会像默认文本字段那样滚动在键盘上方,当您开始输入字段时。我试着查看示例目录中提供的示例应用程序,但是即使没有TextEditController具有这种行为的示例。
有没有办法实现这一点。
提前谢谢。
发布于 2018-04-30 15:41:23
谢谢大家的帮助,@user2785693指出了正确的方向。
我在这里找到了完整的工作解决方案:这里
仅使用滚动或focusNode.listner的问题是,只有当我第一次关注文本框时,它才能工作,但是如果我将键盘最小化并再次单击同一个已经有焦点的文本框,listner回调就不会启动,因此自动滚动代码没有运行。解决方案是在state类中添加"WidgetsBindingObserver“并覆盖"didChangeMetrics”函数。
希望这有助于其他人使颤振形式更友好的用户。
发布于 2020-09-24 09:42:56
如此简单
如果文本字段介于5-10个字段之间
 SingleChildScrollView(
     reverse: true,  // add this line in scroll view
     child:  ...
)发布于 2021-08-20 04:56:35
(2021年8月20日)
我想我的答案可能是解决这个问题的最干净的方法:
@override
Widget build(BuildContext context) {
  /// Get the [BuildContext] of the currently-focused
  /// input field anywhere in the entire widget tree.
  final focusedCtx = FocusManager.instance.primaryFocus!.context;
  /// If u call [ensureVisible] while the keyboard is moving up
  /// (the keyboard's display animation does not yet finish), this
  /// will not work. U have to wait for the keyboard to be fully visible
  Future.delayed(const Duration(milliseconds: 400))
      .then((_) => Scrollable.ensureVisible(
            focusedCtx!,
            duration: const Duration(milliseconds: 200),
            curve: Curves.easeIn,
          ));
  /// [return] a [Column] of [TextField]s here...
}每当键盘启动或消失时,颤振框架将自动调用u. u的build()方法,您可以尝试在IDE中放置一个断点,以便自己找出这种行为。
Future.delayed()将首先返回一个挂起的未来,它将在400毫秒后成功完成。每当Dart运行时看到一个Future时,它就会输入一个非阻塞的I/O时间(=非活动时间=异步时间=挂起时间,这意味着CPU空闲等待完成某些事情)。当Dart运行时等待这个Future完成时,它将继续下面的代码行来构建一个文本字段列。当Future完成后,它将立即跳回这个Future的代码行并执行.then()方法。
https://stackoverflow.com/questions/47338714
复制相似问题