How to Refresh Currently Active Page in Flutter

Every mobile app has at least one page that is always active. This page is usually the main screen of the app, and it’s what users see when they open the app. In most cases, the main screen doesn’t change very often. But sometimes, you may need to refresh it for some reason. In this post, we’ll show you how to refresh the currently active page in Flutter without navigating to other pages then go back just to refresh its data.

@override
  Widget build(BuildContext context) {
    return MyScaffold(
      title: "A Test Page",
      children: [
        Row(
          children: [
            Text("Refresh page"),
          ],
        )
      ],
      floatingButton: FloatingActionButton(
        child: const Icon(Icons.refresh),
        onPressed: () {
          Navigator.pushReplacement(
            context,
            MaterialPageRoute(builder: (BuildContext context) => super.widget),
          );
        },
      ),
    );
  }

Another way is to pop current page then navigate to it again

Navigator.pop(context);  
Navigator.pushNamed(context, "MyPage");

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close