0

当我在下面的列表中选择项目时,它不会改变。如果我单击其他人,则没有任何反应。如何更改 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();
  }

在此处输入图像描述

4

1 回答 1

1

您需要在代码路径中包含一些编写 FireBase 的内容。提供者不会神奇地为您做到这一点。但是,您可以在 notify_listeners() 调用上唤醒各种提供程序或小部件。

于 2020-12-21T21:36:22.920 回答