Flutter Dropdown List Issue

Question

Asked by OneMore on November 23, 2021 (source).

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.

Answer

Question answered by Mojtaba G (source).

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: (_) {},
                                    );
                                  },
                                ),
                              ),
FLUTTER
SHARE: