我正在尝试在 Flutter 中从后台清除应用程序时向用户发送本地通知。我尝试使用 AppLifecycleState 和 WidgetsBindingObserver 来做到这一点。我试图在 Applifecyclestate.detach 中调用发送通知,但是当应用被杀死时代码没有执行。
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.paused:
print('\ncalled detached paused\n');
break;
case AppLifecycleState.resumed:
print('\ncalled detached resumed\n');
break;
case AppLifecycleState.inactive:
break;
case AppLifecycleState.detached:
sendNotification('App should not terminate');
print('\ncalled detached method\n');
break;
}
}
有没有办法做到这一点?