刷新向上滑动以刷新 FUTUREBUILDER 小部件颤动

时间:2021-01-14 08:32:55

标签: flutter flutter-animation

我有一个应用程序,它从 firebase 获取一些数据,然后根据来自 firebase 的数据调用一个类来显示一个小部件。我尝试添加向上滑动刷新,但我不知道将它放在哪里以及在刷新时调用什么。我正在尝试使用 RefreshIndicator。

在这里,我将把我的代码放在其中调用数据库(firebase),然后为数据库中的每个事件创建一个小部件。

如果您需要更多信息,请随时发表评论。非常感谢您的帮助!

FutureBuilder(
      future: databaseReference.once(),
      builder: (context, AsyncSnapshot<DataSnapshot> snapshot) {
        List lists = [];
        if (snapshot.hasData) {
        lists.clear();
        Map<dynamic, dynamic> values = snapshot.data.value;
        values.forEach((key, values) {
            lists.add(values);
        });
        return new ListView.builder(
          primary: false,
          padding: EdgeInsets.only(left:12.0,right:12,bottom: 15,),
          shrinkWrap: true,
          itemCount: lists.length,
          itemBuilder: (BuildContext context, int index) {
          if(lists[index]["Status"]== "Active"){;
          return Container(
          child:EvendWidget(lists[index]["EventImage"], 
                Text(lists[index]["EventName"]).data,
                Text(lists[index]["EventLocation"]+ ", "+lists[index] 
                ["EventCounty"] ).data,
                Text(lists[index]["Date"]+ ", "+lists[index]["Time"]+ 
                " - "+lists[index]["Time"]).data,
                Text(lists[index]["Duration"]+ " H").data,
                Text(lists[index]["Genre"]).data,
                Text(lists[index]["Price"]).data,false));}else{return 
                SizedBox.shrink(); };
            });
        }
        return Container(
          margin: const EdgeInsets.only(top: 300),
          child:CircularProgressIndicator());
    }),

如果您需要更多信息,请随时发表评论。非常感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

您可以像这样使用 RefreshIndicator:

Future<void> _onRefresh() async {
        databaseReference.once();
        return 'success';
      }

return RefreshIndicator(
          onRefresh: _onRefresh,
             child: ListView.builder(
                itemBuilder: (BuildContext context, int index) {
                     --your code here--
                 }

如果您还需要了解任何其他信息,请告诉我。