【问题标题】:How to prevent Flutter widgets resize When the keyboard appears?如何防止 Flutter 小部件在键盘出现时调整大小?
【发布时间】:2020-08-22 09:45:06
【问题描述】:

当键盘出现时,Flutter 小部件会调整大小。如何在不使用

的情况下防止这种情况发生
resizeToAvoidBottomInset : false,

如果我把它设为假,那么我看不到 TextFormField,因为键盘在它上面 那怎么办? 这是我的代码

    return Scaffold(
//      resizeToAvoidBottomInset : false,
      body: Center(
        child: Stack(
          children: <Widget>[
            SizedBox(
              height: MediaQuery.of(context).size.height,
              width: MediaQuery.of(context).size.width,
              child: Image.asset('images/back_ui4.png',fit: BoxFit.fill,),
            ),
            SingleChildScrollView(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  SizedBox(height: 0.7*MediaQuery.of(context).size.height,),
                  TextFormField()
                ],
              ),
            ),
          ],
        ),
      ),
    );

【问题讨论】:

    标签: flutter keyboard scrollview textfield scaffold


    【解决方案1】:
    return Scaffold(
          body: SingleChildScrollView(
            child : Center(
            child: Stack(
              children: <Widget>[
                SizedBox(
                  height: MediaQuery.of(context).size.height,
                  width: MediaQuery.of(context).size.width,
                  child: Image.asset('images/back_ui4.png',fit: BoxFit.fill,),
                ),
                Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      SizedBox(height: 0.7*MediaQuery.of(context).size.height,),
                      TextFormField()
                    ],
                  ),
                ),
              ],
            ),
          ),
        );
    

    【讨论】:

    • 我不想滚动图片
    • 从 SizedBox(Image 的父级)高度移除这个:MediaQuery.of(context).size.height 并设置 ImageView 的高度)
    猜你喜欢
    • 2017-05-03
    • 2021-04-12
    • 2021-12-16
    • 2015-08-21
    • 1970-01-01
    • 2021-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多