'How to retrieve a Array with Map values (String, Boolean) from Firebase and display it as CheckboxListTile?

I have a document inside a collection, with an Array field Orders, which takes Map values {orderName, isReceived (boolean}}. I want retrieve this array inside a StreamBuilder and show it as list of CheckboxTiles. The code below, works but shows me only one element of the array, I have several. Maybe because it doesnt get the Array length. How can i solve this?

                            return ListView.builder(
                              shrinkWrap: true,
                              itemCount: snapshot.data.docs.length,
                              itemBuilder:
                                  (BuildContext context, int index) {
                                var doc =
                                    snapshot.data.docs.elementAt(index);
                                String orderName = doc['orders']
                                    [index]['orderName'];
                                bool isSelected =
                                    doc['orders'][index]['isSelected'];
                                return CheckboxListTile(
                                  tileColor: Colors.white,
                                  title: Text(orderName),
                                  value: isSelected,
                                  onChanged: (bool val) {
                                    setState(() {
                                      isSelected = val;
                                    });
                                  },
                                );
                              },
                            );
          


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source