有没有办法减少TextFormField小部件中实际输入和错误文本之间的间距?目前,表单上显示的错误文本几乎是表单大小的两倍,我希望表单区域大小保持不变,无论是否有错误文本.从下面的图片中,你可以看到它做出了多大的改变,在输入和错误消息之间有很大的空间,这可能需要减少.

Form before errorsForm after errors

以下是其中一个表单字段的示例

Padding(
                padding: EdgeInsets.only(
                    top: 5.0, bottom: 5.0, left: 25.0, right: 25.0),
                child: TextFormField(
                  focusNode: myFocusNodeName,
                  controller: signupNameController,
                  keyboardType: TextInputType.text,
                  textCapitalization: TextCapitalization.words,
                  style: TextStyle(
                      fontFamily: "WorkSansSemiBold",
                      fontSize: 16.0,
                      color: Colors.black),
                  decoration: InputDecoration(
                    border: InputBorder.none,
                    icon: Icon(
                      FontAwesomeIcons.user,
                      color: Colors.black,
                    ),
                    errorText: signupLastNameErrorText,
                    hintText: "Last Name",
                    hintStyle: TextStyle(
                        fontFamily: "WorkSansSemiBold", fontSize: 16.0),
                  ),
                  validator: (value) =>
                      value.isEmpty ? 'Last Name can\'t be empty' : null,
                  onSaved: (value) => _lastname = value,
                ),
              ),

推荐答案

在TextFormField小工具中添加装饰.

InputDecoration(
      contentPadding: EdgeInsets.only(left: 11, right: 3, top: 14, bottom: 14),
      errorStyle: TextStyle(fontSize: 9, height: 0.3),
)

Dart相关问答推荐

具有级联省道的三元算子的奇异行为

如何在将构造函数参数赋给最终变量和传递给超级构造函数之前操作它?

数字到字符串的转换在 Dart 中总是不变的(即没有文化)?

Futures 和异步代码如何在 Dart 中工作?

Flutter - 自定义按钮点击区域

如何在streambuilder中查询firestore文档并更新listview

如何在 Flutter 中忽略整个文件的 lint 规则?

Flutter - 如何自动启用 AnimatedOpacity?

如何使我的Flitter应用程序的导航抽屉(Navigation Drawer)透明?

Flutter热重新加载和热重启不工作

未定义命名参数child.在 Center() 构造函数中

Flutter 构建失败. Android 依赖 'androidx.core:core' 的编译(1.0.0)和运行时(1.0.1)类路径有不同的版本

基于镜子的反射和传统反射有什么区别?

Error: The argument type "String?"can't be assigned to the parameter type"String" because "String?"s nullable and "String"isn't

在 Dart 中编写单元测试的最佳方式是什么?

Dart 中的抽象基类

如何将 3 字节的 unicode 字符写为字符串文字

在我的 angular-cli 元素中从 node-sass 切换到 dart sass

Dart 的服务器端框架

如何将 `ByteData` 实例写入 Dart 中的文件?