-1

I have an app that gets some data from firebase and than calls a class to display a widget based on the data from firebase. I tried adding a swipe up refresh but i have no idea where to put it and what to to call on refresh. I was trying it using the RefreshIndicator.

Here i will put my code in which it calls the database(firebase) and than creates an widget for each event in the database.

If you need any more information, please feel free to comment. Thank you so much for the help!

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());
    }),

If you need any more information, please feel free to comment. Thank you so much for the help!

shorol
  • 790
  • 5
  • 11
Andrei Marin
  • 616
  • 1
  • 6
  • 16

1 Answers1

1

You can use RefreshIndicator like this:

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

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

Let me know if you need to know anything else.

shorol
  • 790
  • 5
  • 11