对于我的应用程序,我有下拉菜单来选择年份。当我选择一个值时,整个应用程序开始调用各种API,我猜这是由于setState。
DropdownButton(
style: const TextStyle(
color: Colors.blue,
),
icon: const Icon(Icons.keyboard_arrow_down),
iconSize: 12,
iconEnabledColor: Colors.red,
hint: const Text(
"MM",
style: TextStyle(
color: Colors.blueAccent,
),
),
items: getYears().map<DropdownMenuItem<String>>((String prod) {
return DropdownMenuItem(
value: prod,
child: Text(prod),
);
}).toList(),
onChanged: (String? newValue) {
setState(() {
year = newValue!;
});
print(year);
},
value: year,
),
当我改变这个下拉菜单的值时,前面下拉菜单的API调用被调用,即使它们没有被触及。有什么建议吗?如何避免对其他下拉菜单使用setState进行不必要的api调用?
1条答案
按热度按时间toe950271#
通知监听器();