I want to create a seperate DropDown List for teacher name , class name and subject name. How can we do it?. I have written a code but it does not change dynamically while the name changes. I have included both my json response and dropdown code.
Here is my json response:
{
"status": {
"code": 200,
"message": "Success"
},
"data": {
"message": "Fetched",
"details": {
"response": [
{
"teacher_id": "2222",
"teacher_name": "abc",
"details": [
{
"session_id": "123",
"class_id": "123",
"batch_id": "123",
"curriculum_id": "123",
"subjects": [
"123"
],
"subject_details": [
{
"sub_id": "12222",
"sub_name": "science"
}
],
"class_name": "10",
"batch_name": "D"
}
]
},
I have written a code but it does not change dynamically while the name changes. here is my code:
DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: Container(
child: DropdownButton(
value: teacherListSelected,
isExpanded: true,
hint: const Text(
'Teacher',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
onChanged: (String? newVal) {
setState(() {
this.teacherListSelected = newVal;
print(teacherListSelected);
});
},
items: teacherList?['response']
.map<DropdownMenuItem<String>>((item) {
return DropdownMenuItem<String>(
child: Text(item['teacher_name']),
value: item['teacher_id'],
);
}).toList()),
),
),
),
DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: Container(
child: DropdownButton(
value: teacherClassSelected,
isExpanded: true,
hint: const Text(
'class',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
onChanged: (String? newVal) {
setState(() {
this.teacherClassSelected = newVal;
print(teacherClassSelected);
});
},
items: teacherList?['response'][1]['details']
.map<DropdownMenuItem<String>>((item) {
return DropdownMenuItem<String>(
child: Text(item['class_name']),
value: item['class_name'],
);
}).toList()),
),
),
),
DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: Container(
child: DropdownButton(
value: teacherSubjectSelected,
isExpanded: true,
hint: const Text(
'subject',
style: TextStyle(
fontWeight: FontWeight.bold,
),
), items: [],
// onChanged: (String? newVal) {
// setState(() {
// this.teacherListSelected = newVal;
// getTeacherData();
// print(teacherListSelected);
// });
// },
// items: teacherList?['data']
// .map<DropdownMenuItem<String>>((item) {
// return DropdownMenuItem<String>(
// child: Text(item['teacher_name']),
// value: item['teacher_id'],
// );
// }).toList()),
),
),
),
),