在Flutter中使用DropDownField时无法获得价值。

问题描述 投票:0回答:1

我使用的是下面的 DropDownField 的代码,但我无法将该值存储在国家列表中。String selectedValue. 我正在使用 DropDownField 在flutter中的依赖性。

List<String> countries = [
    'FRANCE',
    'USA',
    'JAPAN',
  ];

String selectedValue;
    DropDownField( icon: Icon(Icons.map),
                  required: false,
                              hintText: 'Choose a country',
                              labelText: 'Country',
                              items: countries,
                              setter: (dynamic newValue) {
                                setState(() {

                                  selectedValue = newValue;
                                });
                              }),
flutter dropdown
1个回答
1
投票

你应该使用onChanged从DropDown中获取值。

 DropDownField( icon: Icon(Icons.map),
                  required: false,
                              hintText: 'Choose a country',
                              labelText: 'Country',
                              items: countries,
                              onChanged:(value){
                                   print(value)
                              }
                              }),
© www.soinside.com 2019 - 2024. All rights reserved.