flutter: 弹出键盘后内容溢出屏幕

https://dev.to/rubensdemelo/flutter-forms-improving-uiux-with-singlechildscrollview-36gd
使用SingleChildScrollView

Widget build(BuildContext context) {
    return Center (
      child: SingleChildScrollView(
          child: Center(
            child: Card(
              margin: const EdgeInsets.all(12.0),
              // 可以设置半径为12的圆角
              shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12.0))),
              elevation: 15.0,  //设置阴影
              child: Column(
                mainAxisSize: MainAxisSize.min, // 主轴上最小,不会有多余空间
                children: [
                  ClipRRect(
                      borderRadius: BorderRadius.circular(4),
                      child: Image.asset(
                        'assets/img/login.png',
                      )
                  ),
                  Container(
                      padding: const EdgeInsets.all(8.0),
                      child: Column(
                          children: [
                            TextField(
                              obscureText: false, // 是否为密码
                              decoration: InputDecoration(
                                labelText: 'Account',
                                enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey)),
                              ),
                            ),
                            TextField(
                              maxLength: 10,//最大长度,设置此项会让TextField右下角有一个输入数量的统计字符串
                              obscureText: true,
                              decoration: InputDecoration(
                                labelText: 'Password',
                                enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey)),
                              ),
                            ),
                          ]
                      )
                  ),
                  ButtonTheme.bar(
                    // make buttons use the appropriate styles for cards
                    child: ButtonBar(
                      children: [
                        FlatButton(
                          child: const Text('LOGIN'),
                          onPressed: () {
                            print("登入失败");
                          },
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          )
      ),
    );
  }

你可能感兴趣的:(flutter: 弹出键盘后内容溢出屏幕)