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



我有一个应用程序,它从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());
    }),

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

您可以像这样使用RefreshIndicator:

Future<void> _onRefresh() async {
        databaseReference.once();
        return 'success';
      }
return RefreshIndicator(
          onRefresh: _onRefresh,
             child: ListView.builder(
                itemBuilder: (BuildContext context, int index) {
                     --your code here--
                 }

如果你还需要了解什么,请告诉我。

最新更新