I have an Api Which I want to show in my drop down menu of flutter app.
I am able to get lists in simple Text widget but not able to fetch in DropDownButton.
Here is sample of my code
_getAllCategories() async {
var categories = await _categoryService.getCategories();
var _list = json.decode(categories.body);
List<Category> results = [];
_list['data'].forEach((data) {
var model = Category();
model.id = data["id"];
model.name = data["categoryName"];
model.icon = data["categoryIcon"];
results.add(model);
});
if (mounted) {
setState(() {
_categoryList = results;
});
}
}
and I am getting my result using
ListView.builder(
itemCount: _categoryList.length,
itemBuilder: (context, index){
return Text(_categoryList[index].name,style: TextStyle(fontSize: 25),);
},
),
