0

I have a problem. Please help. I just started the program in a flutter. I want to display my array list(foto) to DropDownButton. array list in firebase ,

 final List<String> listCategorys = FirebaseFirestore.instance
      .collection('shoppingList')
      .doc('category');
  String categoryName = 'fruit';
 DropdownButton<String>(
                    focusColor: Colors.white,
                    value: categoryName,
                    style: const TextStyle(color: Colors.white),
                    iconEnabledColor: Colors.black,
                    items: listCategorys
                        .map<DropdownMenuItem<String>>((String value) {
                      return DropdownMenuItem<String>(
                        value: value,
                        child: Padding(
                          padding: const EdgeInsets.only(
                            left: 42,
                          ),
                          child: Text(
                            value,
                            style: const TextStyle(
                              color: Colors.black,
                              fontSize: 18,
                            ),
                          ),
                        ),
                      );
                    }).toList(),
                    hint: const Text(
                      "Select categories",
                      style: TextStyle(
                          color: Colors.black,
                          fontSize: 24,
                          fontWeight: FontWeight.w500),
                    ),
                    onChanged: (String? value) {
                      setState(() {
                        categoryName = value!;
                      });
                    },
                  ),

when I create a rigid array final List<String> listCategorys = ['fruit', 'vegetables' ...] it works, but I won't get all data in firebase

Gwhyyy
  • 7,554
  • 3
  • 8
  • 35
Patryk
  • 3
  • 3

1 Answers1

0

Your Query should be

 DocumentSnapshot snap = await FirebaseFirestore.instance
      .collection('shoppingList')
      .doc($yourDocumentID).get();

 List<String> listOfCategory = List.from(snap.data['category']); 
MANISH DAYMA
  • 1,126
  • 3
  • 18
  • Thank You very much for your answer but when i change as in yours idea i have error "A value of type 'Future>>' can't be assigned to a variable of type 'DocumentSnapshot'. Try changing the type of the variable, or casting the right-hand type to 'DocumentSnapshot'." ... – Patryk Nov 21 '22 at 15:10
  • when changing Future>> snap = FirebaseFirestore[...] have error by snap.data['category] - "The getter 'data' isn't defined for the type 'Future>>'. Try importing the library that defines 'data', correcting the name to the name of an existing getter, or defining a getter or field named 'data'." – Patryk Nov 21 '22 at 15:10