Flutter InputDecorationを使ってTextFormFieldのバリデーションエラーテキストの色を設定する

環境
Windows11 pro 64bit
Flutter 3.3.7

構文

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
decoration: InputDecoration(
errorStyle: TextStyle(
color: xxx,
),
),
decoration: InputDecoration( errorStyle: TextStyle( color: xxx, ), ),
decoration: InputDecoration(
  errorStyle: TextStyle(
    color: xxx,
  ),
),

TextFormFieldのバリデーションエラーのテキストカラーを設定するには、InputDecorationを使います。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
TextFormField(
decoration: InputDecoration(
errorStyle: TextStyle(
color: Colors.red,
),
),
validator: (value) => 'エラーメッセージ',
),
TextFormField( decoration: InputDecoration( errorStyle: TextStyle( color: Colors.red, ), ), validator: (value) => 'エラーメッセージ', ),
TextFormField(
  decoration: InputDecoration(
    errorStyle: TextStyle(
      color: Colors.red,
    ),
  ),
  validator: (value) => 'エラーメッセージ',
),

説明
TextFormFieldの引数「decoration」にInputDecorationを指定します。
InputDecorationの引数「errorStyle」にTextStyleを指定します。
TextStyleの引数「color」にエラーテキストの色を指定します。

Flutter

Posted by arkgame