我需要在下拉列表中显示教师姓名列表,当我单击教师姓名时,需要转到该教师各自的作业。我是 flutter 新手,我该怎么做?
最佳答案
您应该尝试创建自己的拖拽 API 1. 选择所有教师 2. 获取所选用户的主题。
String sid;
List data = List();
String url = "https://example.com/teacher";
//your all teacher api call
Future fetchTeacher() async {
var result = await http.get(url, headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
});
var jsonData = json.decode(result.body);
setState(() {
data = jsonData;
});
return jsonData;
}
// add your API call with ininState() function
@override
void initState() {
super.initState();
fetchTeacher();
}
// Your Widget for All teachers dropdown list
DropdownButtonHideUnderline(
child: DropdownButton(
value: sid,
hint: Text("Select Stockiest",
style: TextStyle(color: Colors.black)),
items: data.map((list) {
return DropdownMenuItem(
child: Text(list['name']),
value: list['sid'].toString(),
);
}).toList(),
onChanged: (value) {
setState(() {
sid = value;
});
},
),
),
为选定的教师科目尝试相同的 API 函数,网址如下:
String url = "https://example.com/teacher"+sid;
传递所选教师的上述网址的 ID,并将此 ID 推送到您的主题小部件,您将获得所选教师的主题数据
关于flutter - 如何在数据来自API的flutter中创建下拉列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68418081/