【问题标题】:keypad hides my textformfield dart flutter is there any solution, it tried a lot nothing worked键盘隐藏了我的 textformfield 飞镖颤振有什么解决方案吗,它尝试了很多都没有用
【发布时间】:2021-03-19 19:05:44
【问题描述】:

这是我的表单

 Widget verticalList = new ListView(
        shrinkWrap: true,
        children: [
          Container(
            color:Colors.white,
            width: MediaQuery.of(context).size.width,
            child:  Form(
              key: _formKey,
              child:Column(
                //  shrinkWrap: true,
                mainAxisSize:MainAxisSize.min,
                children: [
                      textformField(),
                      textformField(),
                      textformField(),
                      textformField(),
                      textformField(),
                      ........
                      .........

                ],
              ),
            ),
          ),
        ],
    );

下面是脚手架部分完整代码

return Scaffold(
      resizeToAvoidBottomInset: true,
      body: Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
              begin: Alignment.topCenter,
              end: Alignment.center,
              stops: [0.0,1,1.2],
              colors: <Color>[
                Color(0xff19879a),
                Color(0xff000e11),
                Color(0xff000e02),
              ],
            ),
          ),
          child: Column(
              children:[
                Container(
                  height: 160,
                  width: MediaQuery.of(context).size.width,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Expanded(flex:3,
                        child: Container(
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.end,
                            children: [
                              FittedBox(child: Text("Firm Details",style: GoogleFonts.lato(color: Color(0xfffbfbfb),fontSize: 1.8*SizeConfig.textMultiplier))),
                              SizedBox(height: 0.5*SizeConfig.heightMultiplier,),
                              Padding(
                                padding: const EdgeInsets.only(left:30.0),
                                child: Text(
                                 "Please select the category that best describes your business model.",
                                  textAlign: TextAlign.right,
                                  style: GoogleFonts.lato(
                                      color: Color(0xffb3fbfbfb),
                                      fontSize: 1.5*SizeConfig.textMultiplier),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                      Expanded(
                        flex: 2,
                        child: Container(
                          width: 10.0*SizeConfig.widthMultiplier,
                          height: 10.0*SizeConfig.heightMultiplier,
                          child: Image.asset(
                            "assets/images/firmDetail.png",
                            width: 10.0*SizeConfig.widthMultiplier,
                            height: 10.0*SizeConfig.heightMultiplier,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                Expanded(
                  child: Container(
                  decoration: BoxDecoration(
                      color: Colors.white,
                      border: Border.all(
                        color: Colors.white,
                      ),
                      borderRadius: BorderRadius.only(topLeft:Radius.circular(30),topRight: Radius.circular(30))
                  ),
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Expanded(flex:1,child: horizontalList1),
                      Expanded(flex:5,child:verticalList,),
                    ],
                  ),
      ),)
  ]
    )
    ),
    );

请帮助我尝试了很多都没有用, 我的代码有什么问题吗

请帮助我尝试了很多都没有用, 我的代码有什么问题吗

keypad 隐藏了我的 textformfield 飞镖颤振有什么解决办法吗,试了很多都没用

【问题讨论】:

    标签: forms flutter dart textformfield


    【解决方案1】:

    用这个填充包裹表单:

    Padding(
      padding: EdgeInsets.only(
        bottom: MediaQuery.of(context).viewInsets.bottom
      ),
    )
    

    【讨论】:

      【解决方案2】:

      将所有内容包装在 SingleChildScrollView 小部件中,您可以在显示键盘时滚动。

      Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text('Your Title'),
        ),
        body: SingleChildScrollView(
          child:  _buildPage(),
        ),
      );}
      

      如果您希望在用户滚动时隐藏键盘,请使用 NotificationListener 将其全部包裹起来。

      body: NotificationListener<ScrollUpdateNotification>(
        onNotification: (notification) {
            // dismiss keyboard on scroll if user initiated the scroll (ie dragDetails != null)
            if (notification.dragDetails != null) {
              FocusScope.of(context).unfocus();
            }
            return true;
        },
        child: SingleChildScrollView(
          child: _buildPage(),
        ),
      );
      

      【讨论】:

      • 在这里我添加了此代码,但出现错误“未为类 '_firmDetailsPageState' 定义 getter 'notification'。尝试将名称更正为现有 getter 的名称,或定义 getter 或名为“通知”的字段。如果 (notification.dragDetails != null) { ^^^^^^^^^^^
      • 对不起 Navas,我的复制/粘贴错误。我已经更新了上面的示例。 'notification'是onNotification传入的回调参数:
      • 我改变了,但它仍然是隐藏我的文本字段
      • 如果您需要任何进一步的帮助,请显示一些正在发生的屏幕截图并显示您的代码以及更改。
      • 这里是视频文件imgur.com/a/ZnOfg5C的链接,我的问题是键盘在输入时总是隐藏我的文本字段,我改变了我的代码添加了上面的代码仍然没有改变,我的完整代码在以上部分
      猜你喜欢
      • 2020-05-04
      • 2020-10-16
      • 1970-01-01
      • 2019-09-28
      • 1970-01-01
      • 2021-03-28
      • 1970-01-01
      • 1970-01-01
      • 2021-11-18
      相关资源
      最近更新 更多