You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Flutter中TextFormField错误提示信息的字体大小?

调整Flutter TextFormField错误提示的字体大小

要修改TextFormField错误提示的字体大小,只需在InputDecoration中配置errorStyle属性,通过TextStyle指定字体尺寸即可。

修改后的完整代码示例:

TextFormField(
  maxLength: 50,
  decoration: const InputDecoration(
    label: Text('Name'),
    // 配置错误提示的字体大小
    errorStyle: TextStyle(fontSize: 12),
  ),
  keyboardType: TextInputType.text,
  validator: (value) {
    if (value == null ||
        value.isEmpty ||
        value.trim().length <= 1 ||
        value.trim().length > 50) {
      return "Must be between 1 and 50 characters";
    }
    return null;
  },
),

你可以根据需求调整fontSize的数值,同时也能在errorStyle里设置其他样式,比如字体颜色、字重等。

内容的提问来源于stack exchange,提问作者Abdullah zain Haider

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 06:42:18