FirebaseAnimatedList 实时更改内容

Jor*_*ira 4 dart firebase firebase-realtime-database flutter

我想知道如何使用新查询、更改路径的新内容重建 FirebaseAnimatedList。

new Flexible(
              child: new FirebaseAnimatedList(
                  query: query,
                  sort: (DataSnapshot a, DataSnapshot b) =>
                      b.key.compareTo(a.key),
                  itemBuilder: (BuildContext context, DataSnapshot snapshot,
                      Animation<double> animation, int index) {...})
Run Code Online (Sandbox Code Playgroud)

当我实时更改查询时,它不会更改列表中的结果:

setState(() {
  query = "another/path";
});
Run Code Online (Sandbox Code Playgroud)

Jor*_*ira 5

每次更改查询时,我都可以更改密钥,我不确定是否是最好的方法,但是正在工作:

new Flexible(
              child: new FirebaseAnimatedList(
                  key: _key,
                  query: query,
                  sort: (DataSnapshot a, DataSnapshot b) =>
                      b.key.compareTo(a.key),
                  itemBuilder: (BuildContext context, DataSnapshot snapshot,
                      Animation<double> animation, int index) {...})


setState(() {
  query = "another/path";
  _key = Key('anotherkey');
});
Run Code Online (Sandbox Code Playgroud)