0

I passed data from RTDB into a map.

This is the RTDB structure: RTDB

I extracted the data using schoolList['Kỹ thuật và Công nghệ']['oisp']['title'] (I called the map that was holding the data schoolList) and printed the data. It worked fine: I/flutter (28664): Quốc tế Đại học Bách khoa TP.HCM.

I tried to use data to make widget to I created a loop that would auto-generate widgets inside a list:

              HorizontalScroll(
                tile: <Widget>[
                  for (var category in categories)
                    for (var school in featuredSchool)
                      if (schoolList[category][school] != null)
                        HomeCard(
                          name: schoolList[category][school]['title'],
                          category: schoolList[category][school]
                              ['category'],
                          networkImage: NetworkImage(schoolList[category]
                              [school]['imgcard']),
                          function: () {
                            Navigator.push(
                              context,
                              MaterialPageRoute(builder: (context) {
                                return SchoolPage(
                                  school: schoolList[category]
                                      [school],
                                );
                              }),
                            );
                          },
                        )
                ],
              ),
            ),

and it did not work. But specifying to a specific data and create a single widget worked:

HomeCard(
  name: schoolList['Kỹ thuật và Công nghệ']['oisp']['title'],

How can I auto-generate my widgets? Thanks in advance!!!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
ttng_
  • 17
  • 5

0 Answers0