I want to fill a Dropdown Button with Firestore and i can get the data but i can't put it on the dropdown.
I had already identified the problem and it's the item list of the DropDown Button but i don't understand what is happening.
When i put the valor null on 'items' it works (doesn't show error) but doesn't show anything (obviously).
Here is my code.
StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('usuarios/$id/ubications')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
const Text("Error");
} else {
List<DropdownMenuItem> ubicationItems = [];
print(snapshot.data.documents.length);
for (int i = 0; i < snapshot.data.documents.length; i++) {
DocumentSnapshot snap = snapshot.data.documents[i];
//_accountType.add(snap['ubication']);
ubicationItems.add(DropdownMenuItem(
child: Text(
snap['ubication'],
),
value: "${snap['ubication']}",
));
}
print(ubicationItems.length); //it has the data
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
DropdownButton(
items: ubicationItems,
onChanged: (selectedType) {
print('$selectedType');
setState(() {
selectedType = selectedUbication;
});
},
value: selectedUbication,
isExpanded: true,
hint: new Text("ubication"),
),
],
);
}
}),This is the error:
I/flutter (14877): Another exception was thrown: 'package:flutter/src/material/dropdown.dart': Failed assertion: line 609 pos 15: 'items == null || items.isEmpty || value == null || items.where((DropdownMenuItem item) => item.value == value).length == 1': is not true.
i used this example like guide: https://github.com/whatsupcoders/FlutterDropDown/blob/master/lib/main.dart
I hope someone can help me, thanks.