How to auto refresh previous page (first page) using flutter_bloc in Flutter

Issue

SCENARIO

There are two pages, first page is HomePage where it fetch the api data automatically with the help of flutter_bloc package. In the homepage (first page) there is also a button which goes to second page (Settings Page) with the help of this code Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) => SettingsPage()));. In the Second page there are 3 radiobuttons and one button at the bottom (Button name is Save). And when i click on save button it goes back to homepage with the help of this code Navigator.pop(context);

QUESTION

When i select any of the radiobutton and click on button at the bottom, how do i refresh or rebuild the homepage and fetch the api data again.

Solution

You can pass the instance of the bloc for the home page to the settings page bloc, and then when you press save, or when you change the options in settings, trigger an event in the home page bloc that fetches the updated data and emits the result in the home page bloc output stream.

Answered By – Kris

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *