How to restart Flutter app on android without closing and opening the app again?
i use these MyApp.restartApp() and SystemNavigator.pop()
but the problem is that it is not user friendly, me too as i develope the application closing and re opening the app is bit anoying.
i dont know the proper term on what my point is but you may get my idea.
Try this: I use this when i need to restart app for example internet is restored after being down
in your main
runApp(const RestartWidget(child: const MyApp()));
create restart widget
class _RestartWidgetState extends State<RestartWidget> {
Key key = UniqueKey();
void restartApp() {
setState(() {
key = UniqueKey();
});
}
@override
Widget build(BuildContext context) {
return KeyedSubtree(
key: key,
child: widget.child,
);
}
}
then in your main add this
runApp(const RestartWidget(child: const MyApp()));
Then to trigger restart say in a button
onTap: (){
RestartWidget.restartApp(context);
},
如果您在 IDE 中,当您的应用程序正在运行时,您可以尝试通过按r或R键来执行热重载的热重启。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.