首页 > 解决方案 > 展开的小部件必须放在 Flex 小部件内

问题描述

新来的扑腾。这是我的代码。有人能告诉我哪里错了吗?另外,我不希望在键盘出现时隐藏 TextField。除了使用 KeyboardAvoider 之外,还有其他方法可以做到这一点吗?

return Scaffold(
        resizetoavoidbottomInsets: true,
    body: SafeArea(
      child: Stack(
        children: <Widget>[
            Container(height: MediaQuery.of(context).size.height), 
          Image.asset('images/otp.jpeg'), 
          Positioned(
            top: MediaQuery.of(context).size.height * 0.3,
            child: Container(
              width: MediaQuery.of(context).size.width,
              height: MediaQuery.of(context).size.height * 0.7,

              child: ListView(
                children: <Widget>[

                Text('Welcome), 
                  Spacer(
                    flex: 1,
                  ),
                  Container(
                    width: MediaQuery.of(context).size.width * 0.8,
                    height: MediaQuery.of(context).size.height * 0.07,

                    child: Form(

                      key: _formKey,
                      child: TextFormField(), 



                    ),
                  ),
                 Spacer()


                ],
              ),
            )
);

标签: flutter

解决方案


当键盘出现时,我不希望 TextField 被隐藏。除了使用 KeyboardAvoider 之外,还有其他方法可以做到这一点吗?

resizeToAvoidBottomInsets将脚手架上的属性设置为 true

至于标题:

展开的小部件必须放在 Flex 小部件内

您将一个Flex小部件放在Widget不扩展的 a 中Flex(例如ColumnRowextend Flex,因此您应该删除Expanded或将其包装在Widget扩展的 a 中Flex


推荐阅读