[Flutter]DropdownButtonFormFieldのテキストの色を設定するには?

Flutter

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

DropdownButtonFormFieldのテキストの色を設定する方法を紹介します。

スポンサーリンク

方法

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

DropdownButtonFormFieldのテキストの色を設定するには、引数「style」を使います。

まず、DropdownButtonFormFieldの引数「style」にTextStyleを指定します。

そして、TextStyleの引数「color」にテキストの色を指定をします。

DropdownButtonFormField(
  style: TextStyle(
    color: /*テキストの色*/,
  ),
  value: _text,
  items: [
    ・・・
  ],
  onChanged: (String? value) {
   ・・・
  },
),

引数「style」を使えば、DropdownButtonFormFieldのテキストの色を設定することが出来ます。

使用例

以下は、使用例です。

DropdownButtonFormField(
  style: TextStyle(
    color: Colors.pink,
  ),
  value: _text,
  items: [
    DropdownMenuItem(
      child: Text('Hello'),
      value: 'Hello',
    ),
    DropdownMenuItem(
      child: Text('Hola'),
      value: 'Hola',
    ),
    DropdownMenuItem(
      child: Text('こんにちは'),
      value: 'こんにちは',
    ),
  ],
  onChanged: (String? value) {
    setState(() {
      _text = value ?? 'Hello';
    });
  },
),

コメント

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