Flutter 使用提供程序更新DropdownButton
当我选择下面列表中的项目时,它不会更改。如果我单击其他按钮,则什么也不会发生。 如何更改firestore和UI的此值? 我知道,我需要更新Flutter 使用提供程序更新DropdownButton,flutter,dart,drop-down-menu,provider,flutter-state,Flutter,Dart,Drop Down Menu,Provider,Flutter State,当我选择下面列表中的项目时,它不会更改。如果我单击其他按钮,则什么也不会发生。 如何更改firestore和UI的此值? 我知道,我需要更新value:constantValue,这段代码,但我如何使用提供者来更新呢 这里,按钮: Widget dropdownButton(BuildContext context) { String constantValue = "League Of Legends"; return DropdownButton( value:
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());
您需要在代码路径中包含编写FireBase的内容。提供商不会神奇地为您这样做。但是,您可以让各种提供者或小部件在notify_listeners()调用时醒来。这个问题需要详细说明。更新Firestore的代码是什么?您是否正在使用
ChangeNotifierProvider
?(它需要包装您想要更改的内容——或者您希望更新Firestore,然后从流订阅中刷新?)下拉按钮有一个硬编码值:值:constantValue,
——但该值必须是PostProvider
中的值,如:上下文。watch().postCategory
。我已经包含了,但它仍然没有更改
String _postCategory;
String get postCategory => _postCategory;
set postCategory(String value) {
_postCategory = value;
notifyListeners();
}