I want to achive DropDownMenu as dynamic as Flutter Appbar widget.
here is my previous static dropdown :
DropdownButton<int>(
value: allCategoryProductC.selectedValue,
icon: KText(text: ' '),
dropdownColor: orange,
focusColor: white,
items: <DropdownMenuItem<int>>[
DropdownMenuItem(
child: KText(
text: 'Rajshahi',
color: black,
fontFamily: segoeBoldFonts,
maxLines: 1,
fontSize: 16,
),
value: 1,
),
DropdownMenuItem(
child: KText(
text: 'Dhaka',
color: black,
fontFamily: segoeBoldFonts,
maxLines: 1,
fontSize: 16,
),
value: 2,
),
DropdownMenuItem(
child: KText(
text: 'Rangpur',
color: black,
fontFamily: segoeBoldFonts,
maxLines: 1,
fontSize: 16,
),
value: 3,
),
],
onChanged: (int? value) {
setState(() {
RestartWidget.restartApp(context);
allCategoryProductC.selectedValue = value;
print(value);
RestartWidget.restartApp(context);
});
},
),
I've a Api data, I want to show my data as a List in this dropdown menu widget....
How can I show data ???
This is my Api json data :
{
"locations": [
{
"id": 2,
"location": "Rajshahi",
"slug": "rajshahi",
"status": 1,
"created_at": "2022-01-26T07:25:18.000000Z",
"updated_at": "2022-02-18T13:47:01.000000Z"
}
]
}
This is my Controller:
class CustomerLocationController extends GetxController {
final customerLocationList = RxList<Locations>();
final dio = Dio();
getCustomerLocation() async {
try {
final res = await dio.get(baseUrl + 'customer/location');
final List<Locations> customerLocationData = res.data['locations']
.map((json) => Locations.fromJson(json))
.toList()
.cast<Locations>();
// print(res.data);
customerLocationList.addAll(customerLocationData);
} catch (e) {
print(e);
}
}
How can I fetch data by using this controller....