Rockzy
Rockzy

Reputation: 65

[] is not defined in Map<String, Dynamic>

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. enter image description here

Upvotes: 0

Views: 71

Answers (1)

Peter Haddad
Peter Haddad

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

Related Questions