Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 使用提供程序更新DropdownButton_Flutter_Dart_Drop Down Menu_Provider_Flutter State - Fatal编程技术网

Flutter 使用提供程序更新DropdownButton

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:

当我选择下面列表中的项目时,它不会更改。如果我单击其他按钮,则什么也不会发生。 如何更改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());

您需要在代码路径中包含编写FireBase的内容。提供商不会神奇地为您这样做。但是,您可以让各种提供者或小部件在notify_listeners()调用时醒来。

这个问题需要详细说明。更新Firestore的代码是什么?您是否正在使用
ChangeNotifierProvider
?(它需要包装您想要更改的内容——或者您希望更新Firestore,然后从流订阅中刷新?)下拉按钮有一个硬编码值:
值:constantValue,
——但该值必须是
PostProvider
中的值,如:
上下文。watch().postCategory
。我已经包含了,但它仍然没有更改
     String _postCategory;

     String get postCategory => _postCategory;

  set postCategory(String value) {
    _postCategory = value;
    notifyListeners();
  }