user-interface - 在flutter中我们怎样才能让验证错误消息看起来漂亮

标签 user-interface flutter validationerror error-messaging

enter image description here我正在申请。我分享的登录页面的用户界面。在此我使用了验证,因此它在文本表单字段下方以红色显示验证消息,但它看起来非常难看。有什么方法可以让这个验证错误消息在屏幕上看起来非常好,就像我们在本地使用不同的库一样?

最佳答案

您可以通过InputDecoration自定义表单中的文本字段装饰。小部件,如本例所示:

您的TextFormField小部件:

TextFormField(
  controller: controller,
  decoration: InputDecoration(
    labelText: "Example",
    labelStyle: TextStyle(color: Colors.black),
    errorStyle: TextStyle(color: Colors.red),
    errorBorder: OutlineInputBorder(
      borderSide: BorderSide(color: Colors.red),  
    ),
  ),
  validator: (value) {
    if (value == null || value == '') {
      return "Error";
    }
  },
)

特别是您可以看到这两个属性:

关于user-interface - 在flutter中我们怎样才能让验证错误消息看起来漂亮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58877865/

相关文章:

dart - Flutter:RenderBox 没有布局

python - "global name ' _ ' is not defined"在提高 ValidationError 期间

java - Java 中的垂直文本滚动

android - 使用 AsyncTask 刷新游戏得分 TextView

linux - 在框架而不是终端上获取输出 (Perl-Tk)

php - Laravel 验证规则的自定义错误消息 : Dimensions

html - Codeigniter - 显示数组字段的个别错误消息

user-interface - 如何在 Squeak/Morphic GUI 中使用鼠标滚轮

flutter - 在Flutter中将小部件彼此相邻放置

ios - 即使在黑暗模式下,平台亮度在 iOS 上仍然很亮 - Flutter