DropdownButton Value does not update even after selecting different items.
If default value is null then error message is shown and if I pass any default value (not null) then it never changes to other selected values.
currentCategory is set as default value for DropdownButton.
StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('categories')
.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
currentCategory = snapshot.data.documents[0];
return DropdownButtonHideUnderline(
child:
new DropdownButtonFormField<DocumentSnapshot>(
value: currentCategory,
onChanged: (DocumentSnapshot newValue) {
setState(() {
currentCategory = newValue;
});
print(currentCategory.data['name']);
},
onSaved: (DocumentSnapshot newValue) {
setState(() {
currentCategory = newValue;
});
},
items: snapshot.data.documents
.map((DocumentSnapshot document) {
return new DropdownMenuItem<DocumentSnapshot>(
value: document,
child: Text(
document.data['name'],
),
);
}).toList(),
),
);
}),
help me to resolve this issue. Thanks in advance.