在安卓系统中,在页面开始时立即调用flatter_local_notifications的onSelectNotific



在我的应用程序中,我使用的是flatter_local_notifications插件和onSelectNotification方法,当页面启动时,即使你没有点击通知,也会在Android中立即触发。

这就是我的initState的样子:

@override
void initState() {
super.initState();
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
final android = AndroidInitializationSettings('@mipmap/ic_launcher');
final iOS = IOSInitializationSettings();
final initSettings = InitializationSettings(android: android, iOS: iOS);
flutterLocalNotificationsPlugin.initialize(initSettings,
onSelectNotification: _onSelectNotification);
}

my_onSelectNotification通知位于构建方法之外

在iOS中,一切都能完美运行

我刚刚添加了一个处理这种情况的标志:

bool flagDueNotificationIssue = true; //called once when page opened for the first time
_onSelectNotification(){  
if (Platform.isAndroid && flagDueNotificationIssue) {
flagDueNotificationIssue = false;
return;
}
.... task to do when notification clicked
}

因此,当这个函数第一次被触发时,它将无法工作(即,它有助于解决这个函数的第一个伪调用(,在其他情况下,它将按预期工作。

最新更新