扑;底部溢出280像素

时间:2020-09-11 11:51:46

标签: flutter

我在应用程序中创建了一个注册页面,如下所示,它是一个列表。

enter image description here

但是每当我尝试写东西时,都会收到类似“底部溢出280个像素”的警告...

enter image description here

如果您想看这里是我的代码,无论我单击哪个部分,它都始终发出相同的警告。我尝试使用扩展,但失败了。我哪里出问题了?

class _RegisterPageState extends State<RegisterPage> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(
          child: Column(
            children: [
              Center(child: Text('Register')),
              _paddingWidget('E-mail', 'E-mail'),
              _paddingWidget('Verify', 'verify'),
              Row(
                children: [
                  Padding(
                    padding: const EdgeInsets.only(left: 22, right: 15, top: 15),
                    child: Container(
                      height: 40,
                      width: 158,
                      child: FlatButton(
                        child: Text(
                          'verify code',
                          style: TextStyle(color: Colors.white),
                        ),
                        onPressed: () {},
                        color: Colors.blue,
                        shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(10)),
                      ),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(right: 22, top: 15),
                    child: Container(
                      height: 40,
                      width: 158,
                      child: FlatButton(
                        child: Text(
                          'Send again',
                          style: TextStyle(color: Colors.white),
                        ),
                        onPressed: () {},
                        color: Colors.blue,
                        shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(10)),
                      ),
                    ),
                  ),
                ],
              ),
              _paddingWidget('Name', 'Name'),
              _paddingWidget('Surname', 'Surname'),
              _paddingWidget('Password', 'Password'),
              _paddingWidget('Country', 'Country'),
              _paddingWidget('City', 'City'),
              _paddingWidget('company', 'company'),
              Padding(
                padding: EdgeInsets.all(16.0),
                child: Container(
                  height: 50.0,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(16),
                    color: Colors.grey,
                    boxShadow: [
                      BoxShadow(
                        color: Colors.black.withOpacity(0.05),
                        blurRadius: 6,
                        offset: Offset(0, 2), // changes position of shadow
                      ),
                      BoxShadow(
                        color: Colors.black.withOpacity(0.1),
                        blurRadius: 20,
                        offset: Offset(0, 10), // changes position of shadow
                      ),
                    ],
                  ),
                  child: InkWell(
                    onTap: () {
                      setState(() {});
                    },
                    child: Center(
                      child: Text(
                        'Register',
                        style: TextStyle(
                          fontSize: 16,
                          color: Colors.white,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

_paddingWidget(String hintTextStr, String labelTextStr) {
  return Padding(
    padding: EdgeInsets.only(top: 15, left: 22, right: 22),
    child: TextFormField(
      keyboardType: TextInputType.text,
      style: TextStyle(
        color: Colors.black,
      ),
      decoration: CommonInputStyle.textFieldStyle(
        hintTextStr: hintTextStr,
        labelTextStr: labelTextStr,
      ),
    ),
  );
}

2 个答案:

答案 0 :(得分:1)

您应该将其放在SingleChildScrollView中。它会做两件事对您有帮助。

  1. 删除“溢出”消息。

  2. 帮助您滚动浏览注册表中的不同字段。

答案 1 :(得分:1)

将SingleChildScrollView封闭到正文中的列

return MaterialApp(
      home: Scaffold(
        body: SingleChildScrollView(
          child: Column(
            children: [
              Center(child: Text('Register')),
              _paddingWidget('E-mail', 'E-mail'),
              _paddingWidget('Verify', 'verify'),
              Row(
                children: [
                  Padding(
                    padding: const EdgeInsets.only(left: 22, right: 15, top: 15),
                    child: Container(
                      height: 40,
                      width: 158,
                      child: FlatButton(
                        child: Text(
                          'verify code',
                          style: TextStyle(color: Colors.white),
                        ),
                        onPressed: () {},
                        color: Colors.blue,
                        shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(10)),
                      ),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(right: 22, top: 15),
                    child: Container(
                      height: 40,
                      width: 158,
                      child: FlatButton(
                        child: Text(
                          'Send again',
                          style: TextStyle(color: Colors.white),
                        ),
                        onPressed: () {},
                        color: Colors.blue,
                        shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(10)),
                      ),
                    ),
                  ),
                ],
              ),
              _paddingWidget('Name', 'Name'),
              _paddingWidget('Surname', 'Surname'),
              _paddingWidget('Password', 'Password'),
              _paddingWidget('Country', 'Country'),
              _paddingWidget('City', 'City'),
              _paddingWidget('company', 'company'),
              Padding(
                padding: EdgeInsets.all(16.0),
                child: Container(
                  height: 50.0,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(16),
                    color: Colors.grey,
                    boxShadow: [
                      BoxShadow(
                        color: Colors.black.withOpacity(0.05),
                        blurRadius: 6,
                        offset: Offset(0, 2), // changes position of shadow
                      ),
                      BoxShadow(
                        color: Colors.black.withOpacity(0.1),
                        blurRadius: 20,
                        offset: Offset(0, 10), // changes position of shadow
                      ),
                    ],
                  ),
                  child: InkWell(
                    onTap: () {
                      setState(() {});
                    },
                    child: Center(
                      child: Text(
                        'Register',
                        style: TextStyle(
                          fontSize: 16,
                          color: Colors.white,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }