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

Not able to get value in Using DropDownField in Flutter

我正在使用下面的 DropDownField 代码来列出国家/地区,但我无法将值存储在 String selectedValue 中。我在 flutter 中使用 DropDownField 依赖。

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;
                                });
                              }),

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

 DropDownField( icon: Icon(Icons.map),
                  required: false,
                              hintText: 'Choose a country',
                              labelText: 'Country',
                              items: countries,
                              onChanged:(value){
                                   print(value)
                              }
                              }),