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

时间:2020-04-22 15:24:11

标签: flutter

扑朔迷离。这是我的代码。有人可以告诉我我错了吗? 另外,我不希望在键盘出现时隐藏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()


                ],
              ),
            )
);

1 个答案:

答案 0 :(得分:0)

我不想在键盘出现时隐藏TextField。在那儿 除了使用KeyboardAvoider以外,还有其他方法吗?

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

标题:

展开的窗口小部件必须放在Flex小部件中

您正在将Flex小部件放在Widget不扩展的Flex内(例如ColumnRow扩展Flex ,因此您应该删除Expanded或将其包装在扩展Widget

Flex