首页 > 解决方案 > 在 Flutter 中的 TextField 下显示错误

问题描述

Material Design 允许文本字段通过输入框下方的红色小标签来指示错误:https ://material.io/components/text-fields (见下面的截图)。

有没有办法为TextFieldFlutter 中的某个领域实现这一目标?我希望这是TextFieldor的属性TextEditingController,但还没有找到类似的东西。

显示错误文本字段的屏幕截图

标签: flutterflutter-text

解决方案


它存在于 TextField 的装饰属性中,您也可以使用它的样式属性对其进行样式设置。

     TextField(
        decoration: InputDecoration(
          errorStyle: TextStyle(),
          errorText: 'Please enter something'
        ),
      ),

推荐阅读