本文介绍了FirebaseAnimatedList实时更改内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like to know how to rebuild the FirebaseAnimatedList with a new query, new content changing the path.

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) {...})

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

When i change the query in realtime it not changes the result in the list:

setState(() {
  query = "another/path";
});


推荐答案

每次更改查询时,我都会通过更改Key来工作,我不确定这是否是最好的方法,但是否有效:

I got it working changing the Key each time i change the query, i not sure if is the best way, but is working:

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');
});

这篇关于FirebaseAnimatedList实时更改内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 08:40