【问题标题】:Flutter - when keyboard opens it blocks my textfieldFlutter - 当键盘打开时它会阻止我的文本字段
【发布时间】:2019-10-19 06:06:56
【问题描述】:

当我在表单中选择文本字段时,键盘会弹出,但它会阻止我输入或转到下一个项目。

我添加了一个墨水瓶只是为了摆脱它。

此页面是从我的 Scaffold 所在的主页加载的,并且有一个底部导航栏,当您单击导航栏时,它会将此页面加载到正文中。

我尝试将 resizeToAvoidBottomPadding: false 添加到脚手架,然后将我的代码包装在 SingleChildScrollView 中,但它不起作用。

@override
  Widget build(BuildContext context) {
    return Center(
      key: scaffoldKey,
      child: InkWell(
          splashColor: Colors.transparent,
          onTap: (){
            FocusScope.of(context).requestFocus(FocusNode());
          },
          child: ListView(
            shrinkWrap: false,
            children: <Widget>[
              Container(
                width: MediaQuery.of(context).size.width,
                height: 150,
                decoration: BoxDecoration(
                  image: DecorationImage(
                    fit: BoxFit.fill,
                    image: AssetImage("assets/images/prayer.png"),
                  ),
                ),
              ),
              Container(
                padding: EdgeInsets.all(15.0),
                child: Text(
                  "Share Your Prayer Request",
                  style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
                ),
              ),
              Container(
                padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
                child: Text(
                  "We’d love to pray with you! Please complete the form below to submit your prayer request and our staff will pray for you this week.",
                  style: TextStyle(
                    fontSize: 14,
                  ),
                ),
              ),
              SizedBox(
                height: 10,
              ),
              Form(
                key: _formKey,
                child: Column(
                  children: <Widget>[
                    Container(
                      padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
                      child: Column(
                        children: <Widget>[
                          TextFormField(
                            onSaved: (val) {
                              if (val == '') {
                                newPrayer.name = "Name Not Entered";
                              } else {
                                newPrayer.name = val;
                              }
                            },
                            cursorColor: Colors.lightGreen,
                            keyboardType: TextInputType.text,
                            decoration: InputDecoration(
                                labelText: 'Name',
                                //labelStyle: TextStyle(color: myFocusNode.hasFocus ? Colors.black : Colors.grey),
                                hintText: 'Enter Your First and Last Name',
                                focusedBorder: OutlineInputBorder(
                                    borderSide: BorderSide(color: Colors.lightGreen)),
                                border: OutlineInputBorder(borderSide: BorderSide())),
                          ),
                        ],
                      )

                    ),

...

我真的很想在我选择一个文本字段时看到页面向上滚动,这样人们就可以看到它并到达提交按钮。

【问题讨论】:

  • 为什么要将脚手架密钥传递给 Center 小部件?只是想了解整个结构,您可能还想包括脚手架布局,因为脚手架的主体将决定这个小部件的布局方式。

标签: flutter dart


【解决方案1】:

脚手架不是包含其他页面的页面。每个页面都需要自己的脚手架。因此,如果这是它自己的页面,那么这就是您的问题。将您的 Center 小部件包装到它自己的脚手架中。

【讨论】:

  • 我一直认为是在将页面调用到正文中。所以我不想在脚手架里面做脚手架。无论如何我这样做了,我现在可以滚动身体,我只是希望它把它推到键盘上。但这暂时可行。谢谢!
猜你喜欢
  • 1970-01-01
  • 2021-06-19
  • 2019-09-18
  • 2018-11-17
  • 1970-01-01
  • 1970-01-01
  • 2020-03-13
  • 2021-05-15
  • 1970-01-01
相关资源
最近更新 更多