简体   繁体   English

Flutter:出现键盘时向上滚动屏幕

[英]Flutter: Scroll the screen up when keyboard appears

I am trying to build a login screen which contains phone number field on top along with an image and login button at the bottom, as soon as I clicked on the phone number field keyboard rises but my 'login button' hides behind the keyboard, I have used "SingleChildScrollView" so as when the keyboard rises the page becomes scrollable but login button does not appear on the top of the keyboard.我正在尝试构建一个登录屏幕,其中包含顶部的电话号码字段以及底部的图像和登录按钮,一旦我点击电话号码字段键盘升起但我的“登录按钮”隐藏在键盘后面,我已使用“SingleChildScrollView”,以便当键盘上升时页面变为可滚动但登录按钮不会出现在键盘顶部。

Here is the snippet of the code:这是代码片段:

return Scaffold(
  backgroundColor: white.color,
  body: SingleChildScrollView(
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
                  Container(
                        child: Text(
                          'Enter your mobile number',
                          style: TextStyle(
                            fontSize: headSize.fontSize,
                            fontWeight: FontWeight.w400,
                            color: black.color,
                            fontFamily: 'ProductSans',
                          ),
                        ),
                      ),
                      Container(
                        height: screenHeight / 15,
                        child: Center(
                          child: SizedBox(
                            height: screenHeight / 6,
                            width: double.infinity,
                            child: RaisedButton(
                              color: indigo.color,
                              shape: borderRadius,
                              child: Text(
                                "Continue",
....

I can give you a hint as your code is kinda hard to understand, you can use MediaQuery.of(context).viewInsets.bottom.我可以给你一个提示,因为你的代码有点难以理解,你可以使用 MediaQuery.of(context).viewInsets.bottom。 Now the question is what it does and how will it help me.现在的问题是它的作用以及它将如何帮助我。

  1. What it does: It will provide the bottom padding which should be avoided(basically padding taken by system UI in your case keyboard is taking space) by the developer as it is an inherited widget so it will build itself as soon as you open the keyboard.它的作用:它将提供开发人员应该避免的底部填充(基本上由系统UI在您的情况下键盘占用空间),因为它是一个继承的小部件,因此它会在您打开键盘后立即构建.

2.How can I use: you can create an empty container or sized box at the bottom of the column and set its height=MediaQuery.of(context).viewInsets.bottom and wrap your column in a single child scroll view. 2.如何使用:您可以在列底部创建一个空容器或大小框,并设置其 height=MediaQuery.of(context).viewInsets.bottom 并将您的列包装在单个子滚动视图中。

Try replacing with screenHeight / 15 and screenHeight / 6 with for example 100 and check the result.尝试用例如 100 替换screenHeight / 15 and screenHeight / 6并检查结果。

Container(
          height: screenHeight / 15,
          child: Center(
            child: SizedBox(
              height: screenHeight / 6,
              width: double.infinity,
              child: RaisedButton(
                color: indigo.color,
                shape: borderRadius,
                child: Text(
                  "Continue",

By the way you are setting the height of the parent to be smaller than the child.顺便说一句,您将父级的高度设置为小于子级。 I wonder why?我想知道为什么? :) :)

For example, if screenHeight = 100例如,如果 screenHeight = 100

100/15 = 6.6 parent 100/15 = 6.6 父母

100/6 = 16.6 child 100/6 = 16.6 孩子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter:当键盘出现在 android 时屏幕不向上滚动 - Flutter : screen not scrolling up when keyboard appears in android Flutter :- 如何在 Stack 视图上滚动屏幕而不缩小屏幕?(当键盘出现时滚动整个屏幕) - Flutter :- How to scroll the sceen without shrink the screen on the Stack view?(Scroll the the whole screen when the keyboard appears ) 键盘弹出时出现白屏 - White Screen Appears When Keyboard Pop Up Flutter - 如何在键盘出现时使用 SingleScrollView() 滚动整个屏幕,而不仅仅是自动显示文本 - Flutter - how to use SingleScrollView() to Scroll Entire Screen when Keyboard Appears not just text automatically Flutter 出现键盘时 UI 不上移 - Flutter UI not moving up when keyboard appears Flutter 中出现键盘时向上移动文本字段 - Move textfield up when keyboard appears in Flutter 当软键盘出现在 Flutter Webview 插件中时,Single Child Scoll View 不会向上滚动屏幕 - Single Child Scoll View doesn't scroll up screens when soft keyboard appears in Flutter Webview Plugin Flutter:出现键盘时如何缩小图像或滚动到底部 - Flutter: How to shrink images or scroll to bottom when keyboard appears Flutter - 当键盘出现在 android 上时,文本字段不显示 - Flutter - Textfield not showing up when keyboard appears on android 颤抖-键盘出现时,堆栈上的文本如何不显示? - flutter - How can text on stack not up when keyboard appears?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM