dart - 如何使 TextFormField 文本在验证时显示在 TextFormField 行下方

标签 dart flutter

这是我目前面临的情况,因为我希望红色文本出现在该行的正下方而不是上方,因为它看起来有点丑陋,如下所示:

enter image description here

          new Container(
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),
            alignment: Alignment.center,
            decoration: BoxDecoration(
              border: Border(
                bottom: BorderSide(
                    color: Color.fromRGBO(58, 66, 86, 1.0),
                    width: 0.5,
                    style: BorderStyle.solid),
              ),
            ),
            padding: const EdgeInsets.only(left: 0.0, right: 10.0),
            child: new Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                new Expanded(
                  child: TextFormField( // LOGIN SCREEN EMAIL
                    maxLines: 1,
                    keyboardType: TextInputType.emailAddress,
                    autofocus: false,
                    textAlign: TextAlign.left,
                    decoration: InputDecoration(
                      border: InputBorder.none,
                      hintText: LOGIN_SCREEN_EMAIL_HINT,
                      hintStyle: TextStyle(color: Colors.grey),
                    ),
                    validator: (value) => value.isEmpty ? LOGIN_SCREEN_EMAIL_WARNING : null,
                    onSaved: (value) => _email = value,
                  ),
                ),
              ],
            ),
          ),

最佳答案

根据您的代码,该行不是文本字段的行。它是容器底部边框。尝试删除容器底部边框并使用 TextFromField 边框线,如下所示

TextFormField(
  ...
  decoration: InputDecoration(
    focusedBorder: UnderlineInputBorder(
      borderSide: BorderSide(color: Theme.of(context).primaryColor, width: 0.5)
    )
  ),
  ...
)

关于dart - 如何使 TextFormField 文本在验证时显示在 TextFormField 行下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56267523/

相关文章:

user-interface - flutter 持续时间用户输入

dart - 检查一个列表是否包含 Dart 中另一个列表的任何元素

firebase - 如何使用 Flutter/Dart 在 FirebaseDatabase 中获取值的键?

flutter - 类型 'Future<dynamic>' 不是类型转换中类型 'List<dynamic>' 的子类型

flutter - 禁用 TabBar flutter 中的滑动标签

android - 找不到 aapt2-proto-7.0.0-beta04-7396180.jar

Flutter 应用程序无法在 apk-release 中运行,但可以在 Debug模式下运行(即使在授予互联网权限后)

flutter - 如何集成Outlook日历API并在Flutter中从Outlook日历中获取事件?

dart - 如何编写抽象类构造函数,以便在子类中灵活扩展

flutter - 如何将参数传递给命名路由中的小部件?