How to Go Back and Refresh the Previous Page In Flutter??

3 min read
How to Go Back and Refresh the Previous Page In Flutter
How to Go Back and Refresh the Previous Page In Flutter

Consider a case where the user is having a home page which when clicked takes us to another page through navigates, does some operations in then press the back button which takes us back to the home page? Now, the problem is the home page doesn’t get refreshed. So in this article, We will go through How to Go Back and Refresh the Previous Page In Flutter.

How to Go Back and Refresh the Previous Page In Flutter??

You can trigger the API call when you navigate back to the first page like this聽pseudo-code.

class PageOne extends StatefulWidget {
  @override
  _PageOneState createState() => new _PageOneState();
}

class _PageOneState extends State<PageOne> {
  _getRequests()async{

  }
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Center(
        child: new RaisedButton(onPressed: ()=>
        Navigator.of(context).push(new MaterialPageRoute(builder: (_)=>new PageTwo()),)
        .then((val)=>val?_getRequests():null),
      ),
    ));
  }
}

class PageTwo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //somewhere
    Navigator.pop(context,true);
  }
}

Or you can just use a stream if the API is frequently updated, So the new data will be automatically updated inside your Listview Widget

For example with firebase, you can do as shown below:

stream: FirebaseDatabase.instance.reference().child(
      "profiles").onValue

And anytime you change something in the database from the edit profile page, for example, it will reflect on your profile page.

Conclusion:

Thanks for being with us on a Flutter Journey !!!

So in this article, We have been through How to Go Back and Refresh the Previous Page In Flutter.

Do let us know if you have any doubts about Flutter Development!! we would love to assist you 馃檪

Keep Learning !!! Keep Fluttering !!!

Don’t forget to leave feedback in the comments right below!! It keeps the enthusiasm going!!

Flutter Agency聽is our portal Platform dedicated to Flutter Technology and聽Flutter Developers. The portal is full of cool resources from Flutter like聽Flutter Widget聽Guide,聽Flutter Projects,聽Code libs聽and etc.

Flutter Agency is one of the most popular online portals dedicated to聽Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge of聽Flutter.

Leave a Reply