Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 536 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to refresh currently active page in flutter

#1
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.
Reply

#2
I've faced these situations. Instead of passing context, what I did was wrapping the page in a [StreamBuilder][1] with the `null` type, and whenever I need to refresh the page I add a `null` value to sink so the Builder will get updated.

Hope it helps :)


[1]:

[To see links please register here]

Reply

#3
just Simple use

setState(() {});
Reply

#4
try `(context as Element).reassemble();`

reassemble is the function that is used for hot reload

also i think it's better to say your goal and look at other solutions to fix your problem because I don't think this method is reliable.

**EDIT:** there are some useful tips in the comments.
Reply

#5
check code

return RefreshIndicator(
child: CustomScrollView(
controller: _scrollController,
slivers: <Widget>[
SliverAppBar(
primary: false,
expandedHeight: 75,
backgroundColor: Color(0xFFf4eedd),
floating: true,
actions: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/banner.png'),
fit: BoxFit.fill)),
),
],
),
contentView,
],
),
onRefresh: () async {
this._pageLoadController.reset();
await Future.value({});
},
);


Reply

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

Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (BuildContext context) => super.widget));
Reply

#7
Have a look at Provider.

You essentially let's you notify state change from one part of your app to another and then have the target widget redraw.

In particular look at ChangeNotifierProvider

Provider is designed to do this.
Reply

#8
If you are using a calling function for initializing that screen, You just need to recall it again. This example is really useful for upcoming visitors that are using this package:

[To see links please register here]


Example:

This is my screen

class MyPropertyScreen extends StatefulWidget {
@override
_MyPropertyScreenState createState() => _MyPropertyScreenState();
}

class _MyPropertyScreenState extends State<MyPropertyScreen> {

@override
Widget build(BuildContext context) {
return ViewModelBuilder<MyPropertyViewModel>.reactive(
viewModelBuilder: () => MyPropertyViewModel(),
onModelReady: (model) => model.initialized(), //Initalized Function
builder: (context, model, child) =>
Scaffold(
body: ListUI(
recallModel: model
)
));
}
}

class ListUI extends StatelessWidget {
MyPropertyViewModel recallModel;

ListUI ({this.recallModel});


pressReload(){
recallModel.initialized(); //Recall the function again
}
}

If you are using initState() You can find your way around it using this example.
Reply

#9
The same question haunted me for a long time, but in the end I came up with a quite simple answer that works
```
Navigator.pop(context); // pop current page
Navigator.pushNamed(context, "Setting"); // push it back in
```
Reply

#10
Use
setState(({})) ;
in the part of your code where you're accessing the values from an api

like this


if (data["status"]==200){

setState(() {
message= data["message"];
time = data["message"];
});
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through