在 Flutter 中的 TextField 下显示错误

And*_*kin 1 flutter flutter-text

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

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

屏幕截图显示了带有错误的文本字段的外观

小智 6

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

     TextField(
        decoration: InputDecoration(
          errorStyle: TextStyle(),
          errorText: 'Please enter something'
        ),
      ),
Run Code Online (Sandbox Code Playgroud)