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 に答える