[Flutter]TextFormFieldのラベルの色を設定するには?

Flutter

どうも、ちょげ(@chogetarou)です。

TextFormFieldにラベルの色を設定する方法を紹介します。

スポンサーリンク

方法

インターフェース, インターネット, プログラム, ブラウザ, Www

TextFormFieldにラベルを表示するには、InputDecorationを使います。

まず、TextFormFieldの引数「decoration」にInputDecorationを指定します。

そして、InputDecorationの引数「labelStyle」にTextStyleを指定し、TextStyleの引数「color」にラベルの色を指定します。

TextFormField(
  decoration: InputDecoration(
    labelText: 'Name',
    labelStyle: TextStyle(
      color: /*ラベルの色*/,
    ),
  ),
),

これでTextFormFieldにラベルの色を設定することが出来ます。

使用例

以下は、使用例です。

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: TextFormField(
            decoration: InputDecoration(
              labelText: 'Name',
              labelStyle: TextStyle(
                color: Colors.pink,
              ),
              border: OutlineInputBorder(),
            ),
          ),
        ),
      ),
    );
  }

コメント

タイトルとURLをコピーしました