如何在抖动中设置TextFormfield的高度?

时间:2020-09-08 13:10:40

标签: flutter dart layout desktop-application

首先,最近,我开始使用dart代码构建桌面应用。 刚刚建立了一些屏幕,这些屏幕也负责移动设备和网络,因为它们使用了{{1} 但是在尝试根据我的高度设置时出错,因为我用LayoutBuilder包装了TextformField并给出了高度。

当我对登录按钮的Container onClick进行验证时,TextformField的高度出现了问题。

看截图: 在单击登录按钮之前:

enter image description here

当我单击登录按钮而不输入任何值来检查验证时: enter image description here

TextformField的代码段:

TextformField

2 个答案:

答案 0 :(得分:0)

TextFormField从子级继承大小。一种解决方案是在contentPadding中设置InputDecoration。 您已经使用它来填充左侧。您可以进行如下修改:

contentPadding: EdgeInsets.only(left: 10.0, top: 15.0, bottom: 15.0),

答案 1 :(得分:0)

请检查一下

Widget _buildEmailTextField()) {
    return Container(
        height: 35,
        child: Theme(
          data: new ThemeData(
            primaryColor: Color(0xFF262C48),
            primaryColorDark: Color(0xFF262C48),
          ),
          child: Form(
            key: _formKey,
            child: Column(
              children: [
                SizedBox(
                  height: 20,
                ),
                Container(
                  child: TextFormField(
                    keyboardType: TextInputType.emailAddress,
                    validator: (val) {
                      bool emailValid = RegExp(
                              r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+")
                          .hasMatch(val);
                      if (!emailValid) {
                        return 'Invalid Email Address';
                      } else {
                        return null;
                      }
                    },
                    controller: emailController,
                    readOnly: isLoading ? true : false,
                    decoration: InputDecoration(
                      fillColor: Color(0xFFd9d8d8),
                      filled: true,

                      border: new OutlineInputBorder(
                          borderRadius: const BorderRadius.all(
                            const Radius.circular(7.0),
                          ),
                          borderSide:
                              BorderSide(color: Color(0xFF262C48), width: 2.0)),
                      contentPadding: new EdgeInsets.symmetric(
                          vertical: 25.0, horizontal: 10.0),
                      // prefixIcon: Icon(
                      //   Icons.email,
                      //   color: Color(0xFF008577),
                      // ),
                      hintText: 'Email',
                    ),
                  ),
                ),
                
                RaisedButton(
                  onPressed: () {
                    // Validate returns true if the form is valid, otherwise false.
                    if (_formKey.currentState.validate()) {
                      // If the form is valid, display a snackbar. In the real world,
                      // you'd often call a server or save the information in a database.

                      Scaffold.of(context).showSnackBar(
                          SnackBar(content: Text('Processing Data')));
                    }
                  },
                  child: Text('Submit'),
                )
              ],
            ),
          ),
        ),
      );
  }