[Flutter]DropdownButtonFormFieldに枠線をつけるには?

Flutter

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

DropdownButtonFormFieldに枠線をつける方法を紹介します。

スポンサーリンク

方法

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

DropdownButtonFormFieldに枠線をつけるには、引数「decoration」を使います。

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

そして、InputDecorationの引数「border」にOutlineInputBorderを指定します。

DropdownButtonFormField(
  decoration: InputDecoration(
    border: OutlineInputBorder(),
  ),
  value: _text,
  items: [
    ・・・
  ],
  onChanged: (String? value) {
    ・・・
  },
),

引数「decoration」を使えば、DropdownButtonFormFieldに枠線をつけることが出来ます。

使用例

以下は、使用例です。

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var _text = 'Hello';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: DropdownButtonFormField(
            decoration: InputDecoration(
              border: OutlineInputBorder(),
            ),
            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をコピーしました