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

Flutter

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

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

スポンサーリンク

方法

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

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

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

そして、TextStyleの引数でテキストの設定を指定をします。

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

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

使用例

以下は、使用例です。

DropdownButton(
  style: TextStyle(
    fontSize: 25.0, //サイズ
    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をコピーしました