简体   繁体   English

键盘出现时将文本字段滚动到视图中 Flutter

[英]Scroll text fields into view when keyboard comes up Flutter

I have this login page,when i press on text field it should be top of the Keyboard, i tried with following code,but it didn't workout,i tried with singlechildview still same also with listview also didn't work i tried with removing stack and tired with container but it's same,ow i have this code,我有这个登录页面,当我按下文本字段时它应该在键盘的顶部,我尝试使用以下代码,但它没有锻炼,我尝试使用 singlechildview 仍然相同,listview 也没有工作我尝试使用删除堆栈并厌倦了容器,但它是一样的,现在我有这个代码,

 Size size = MediaQuery.of(context).size;
    return new Scaffold(
      resizeToAvoidBottomInset: false,
      body: new Stack(
        children: <Widget>[
          Center(
            child: new Image.asset(
              'assets/images/splash_bg.png',
              width: size.width,
              height: size.height,
              fit: BoxFit.fill,
            ),
          ),
          Center(
            child: new Image.asset(
              'assets/images/clublogo.png',
              width: 150,
              height: 150,
            ),
          ),
          Center(
            child: Padding(
              padding: EdgeInsets.only(top: 250, left: 10, right: 10),
              child: TextField(
                textAlign: TextAlign.center,
                style: TextStyle(color: Colors.white),
                decoration: InputDecoration(
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(
                        color: Colors.orangeAccent[200], width: 2.0),
                    borderRadius: const BorderRadius.all(
                      const Radius.circular(20.0),
                    ),
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(
                        color: Colors.orangeAccent[200], width: 2.0),
                    borderRadius: const BorderRadius.all(
                      const Radius.circular(20.0),
                    ),
                  ),

                  contentPadding: EdgeInsets.all(5),
                  hintText: " Enter Mobile Number",
                  hintStyle: TextStyle(color: Colors.white, fontSize: 15),
                  suffixIcon: Container(
                    decoration: BoxDecoration(
                        border: Border.all(
                          color: Colors.orangeAccent[200],
                        ),
                        borderRadius: BorderRadius.all(
                          Radius.circular(20),
                        )),
                    child: FittedBox(
                      alignment: Alignment.center,
                      fit: BoxFit.fitHeight,
                      child: IconButton(
                        icon: Icon(MdiIcons.arrowRight),
                        iconSize: 33.0,
                        color: Colors.orangeAccent[200],
                        onPressed: () {
                          FocusScope.of(context).requestFocus(FocusNode());
                          print("gfgfg");
                        },
                      ),
                    ),
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );

Please paste below code and change it according to your Widgets..请粘贴下面的代码并根据您的小部件进行更改..

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Container(
          width: MediaQuery.of(context).size.width,
          child: Column(
            children: <Widget>[
              Container(
                margin: EdgeInsets.only(top: 80),
                child: FlutterLogo(
                  size: 200,
                ),
              ),
              Container(
                padding: EdgeInsets.all(10),
                margin: EdgeInsets.only(top: 10),
                child: TextField(
                  controller: _emailController,
                  decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    hintText: "Email",
                    labelText: "Enter Email",
                  ),
                  keyboardType: TextInputType.emailAddress,
                ),
              ),
              Container(
                padding: EdgeInsets.all(10),
                margin: EdgeInsets.only(top: 10),
                child: TextField(
                  controller: _passwordController,
                  decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    hintText: "Password",
                    labelText: "Enter Password",
                  ),
                  obscureText: true,
                ),
              ),
              InkWell(
                onTap: () {
                  _signIn();
                },
                child: Container(
                  decoration: BoxDecoration(
                      gradient: LinearGradient(
                        colors: [Colors.blueAccent, Colors.blue, Colors.black],
                      ),
                      borderRadius: BorderRadius.circular(8)),
                  padding: EdgeInsets.symmetric(horizontal: 30, vertical: 20),
                  margin: EdgeInsets.symmetric(horizontal: 30, vertical: 20),
                  width: MediaQuery.of(context).size.width,
                  child: Center(child: Text("Login with Email")),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

Change resizeToAvoidBottomInset to true to resolve the issue. resizeToAvoidBottomInset更改为true以解决问题。 This makes the textfield move up as keyboard opens.这使得文本字段在键盘打开时向上移动。

在此处输入图像描述

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

相关问题 键盘启动时如何避免页面滚动向上滚动 - How to avoid flutter page scroll up when the keyboard comes up Flutter:出现键盘时向上滚动屏幕 - Flutter: Scroll the screen up when keyboard appears Flutter - 当键盘出来时,ShowModalBottomSheet 没有 go 向上 - Flutter - ShowModalBottomSheet does not go up when the keyboard comes out 当软键盘出现在 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 seamlessly scroll the view when keyboard opened Flutter 文本字段和键盘回避 - Flutter text fields and keyboard avoidance Flutter:编辑我的文本字段时键盘立即消失 - Flutter: keyboard disappears immediately when editing my text fields 颤抖-键盘出现时,堆栈上的文本如何不显示? - flutter - How can text on stack not up when keyboard appears? Flutter 如果键盘覆盖文本字段,则滚动列表视图 - Flutter scroll List view if Keyboard is covering Textfield 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 )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM