当我在下面的列表中选择项目时,它不会改变。如果我单击其他人,则没有任何反应。如何更改 firestore 和 UI 的这个值?我知道,我需要更新value: constantValue,
此代码,但是我如何使用提供程序来做到这一点?
在这里,按钮:
Widget dropdownButton(BuildContext context) {
String constantValue = "League Of Legends";
return DropdownButton(
value: constantValue,
onChanged: (newValue) {
context.read<PostProvider>().postCategory = newValue;
},
items: <String>["League Of Legends", "Steam", "Csgo"]
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList());
}
还有提供者:
String _postCategory;
String get postCategory => _postCategory;
set postCategory(String value) {
_postCategory = value;
notifyListeners();
}