Wie die Umsetzung drop-down-Liste im flattern?

Habe ich eine Liste von Orten, die ich umsetzen will, als eine dropdown-Liste in Flattern. Im ziemlich neu in der Sprache. Hier ist, was ich getan habe.

new DropdownButton(
  value: _selectedLocation,
  onChanged: (String newValue) {
    setState(() {
      _selectedLocation = newValue;
     });
},
items: _locations.map((String location) {
  return new DropdownMenuItem<String>(
     child: new Text(location),
  );
}).toList(),

Dies ist meine Liste der Elemente:

List<String> _locations = ['A', 'B', 'C', 'D'];

Und ich erhalte die folgende Fehlermeldung.

Another exception was thrown: 'package:flutter/src/material/dropdown.dart': Failed assertion: line 468 pos 15: 'value == null || items.where((DropdownMenuItem<T> item) => item.value == value).length == 1': is not true.

Ich nehme an, der Wert _selectedLocation ist immer null. Aber ich bin Initialisierung es so gerne.

String _selectedLocation = 'Please choose a location';

InformationsquelleAutor Chaythanya nair | 2018-03-14

Schreibe einen Kommentar