Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh currently active page in flutter

Tags:

flutter

dart

I have a global function that I call from almost all screens of my app. I am passing context to it. I just want to know if there is a way to refresh the page from which the global function is called depending on context passed to the function?

appResumedPausedLogic(context,[bool isVisitPage]){
  SystemChannels.lifecycle.setMessageHandler((msg)async{
if(msg=='AppLifecycleState.resumed' )
{
  print("------------------------------------ App Resumed-----------------------------");

  var serverConnected= await checkConnectionToServer();
  if(globals.globalCameraOpenedStatus==false)
    if(serverConnected!=1){

      Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => OfflineHomePage()));

    }
    else{
      Navigator.push(context, MaterialPageRoute(builder: (context) => HomePage()));
    }



}
if(msg=='AppLifecycleState.paused' ){
  if(globals.globalCameraOpenedStatus==false)
  locationThreadUpdatedLocation=false;
}

  });
}

My global function redirects users to offline home/home page depending on availability of internet when app is resumed currently. I want it to refresh the currently active screen.

Thanks in advance!

like image 377
Shashank Avatar asked Sep 18 '19 05:09

Shashank


2 Answers

I once used this workaround for a floatingActionButton that reloaded the active page;

Navigator.pushReplacement(
        context,
        MaterialPageRoute(
            builder: (BuildContext context) => super.widget));
like image 23
Chris G. Avatar answered Oct 12 '22 19:10

Chris G.


just Simple use

setState(() {});
like image 135
Vithani Ravi Avatar answered Oct 12 '22 21:10

Vithani Ravi