Reputation: 65
Hey devs Iam trying to make a dropdown menu of categories from firebase.
look this code
_getCategories() async {
List<DocumentSnapshot> data = await _categoryService.getCategory();
print(data.length);
setState(() {
categories = data;
_currentCategory = categories[0].data['category'];
});
}
Here the error is I cant assign 'category' to data, there it is showing me error.
Upvotes: 0
Views: 71
Reputation: 80914
change this:
setState(() {
categories = data;
_currentCategory = categories[0].data['category'];
});
into this:
setState(() {
categories = data;
_currentCategory = categories[0].data()['category'];
});
In the latest update for the firebase plugins, data()
is a method now.
Upvotes: 1