본문 바로가기
ETC/Flutter

[flutter] DropdownButton 사용하기

by dkswnkk 2021. 11. 6.

List<String> dropdownList = ['1', '2', '3'];
String selectedDropdown = '1';

  ..
  ..

DropdownButton(
    value: selectedDropdown,
    items: dropdownList.map((String item) {
      return DropdownMenuItem<String>(
        child: Text('$item'),
        value: item,
      );
    }).toList(),
    onChanged: (dynamic value) {
      setState(() {
        selectedDropdown = value;
      });
    },
  ),

KakaoTalk_Image_2021-08-10-02-01-43

댓글