当用户离开应用程序后返回应用程序时,刷新主屏幕.应用程序仍然在手机的内存中



我有一个单屏幕应用程序,现在,当用户离开应用程序不到一分钟左右,应用程序仍然在手机ram上,用户可以从他离开的地方选择。

我想要一个功能,当用户离开应用程序后回到应用程序屏幕,屏幕可以刷新,因为内容改变..

假设您使用的是有状态小部件,请为其添加一个widgetbinding观察者

class _yourClassState extends State<YourClass>
with WidgetsBindingObserver {
// Here you can override initstate, build etc
}

现在widgetBindingObserver也将允许你重写didChangeAppLifeCycleState,这将允许你捕获应用程序的状态。

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.resumed:
print("app in resumed from background"); //you can add your codes here
break;
case AppLifecycleState.inactive:
print("app is in inactive state");
break;
case AppLifecycleState.paused:
print("app is in paused state");
break;
case AppLifecycleState.detached:
print("app has been removed");
break;
}
}

相关内容