简体   繁体   中英

Flutter Dropdown List Issue

I have one phpmysql database. And i am fetching data from database. And i wanna showing my categories data into my dropdown button. But its showing only first data. Thats my code.

SizedBox(
                                width: context.dynamicWidth(5),
                                height: context.dynamicHeight(5),
                                child: ListView.builder(
                                  shrinkWrap: true,
                                  itemCount: snap.length,
                                  itemBuilder: (context, index) {
                                    var categoryList =
                                        snap[index]['categoryName'];
                                    return DropdownButton<String>(
                                      items: <String>[
                                        categoryList,
                                      ].map((String value) {
                                        return DropdownMenuItem<String>(
                                          value: value,
                                          child: Text(value),
                                        );
                                      }).toList(),
                                      onChanged: (_) {},
                                    );
                                  },
                                ),
                              ),

Thats show only first data. Thx for helping.

Try

    var categoryList = snap[index];

instead of

    var categoryList = snap[index]['categoryName'];

I don't know your snap list type but hope this work's

SizedBox(
                                width: context.dynamicWidth(5),
                                height: context.dynamicHeight(5),
                                child: ListView.builder(
                                  shrinkWrap: true,
                                  itemCount: snap.length,
                                  itemBuilder: (context, index) {
                                    return DropdownButton<String>(
                                      items: snap.map((value) {
                                        return DropdownMenuItem<String>(
                                          value: value['categoryName'],
                                          child:Text(value['categoryName']),
                                        );
                                      }).toList(),
                                      onChanged: (_) {},
                                    );
                                  },
                                ),
                              ),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM