简体   繁体   English

在 Android 的页面开始时立即调用 flutter_local_notifications 的 onSelectNotification 方法(在 iOS 中没有此类问题)

[英]onSelectNotification method of flutter_local_notifications called immediately on page start in Android (in iOS no such issue)

In my app I am using flutter_local_notifications plugin and onSelectNotification method triggered immediately in Android when page started, even if you don't click the notification.在我的应用程序中,我使用flutter_local_notifications 插件和onSelectNotification方法在页面启动时立即在Android 中触发,即使您不单击通知也是如此。

This is how my initState looks:这就是我的 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 notification located outside of the build method我的_onSelectNotification通知位于构建方法之外

In iOS everything works perfectly在 iOS 中一切正常

I have just added a flag for handling this case:我刚刚添加了一个标志来处理这种情况:

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
}

So when this function triggered for the first time it will not work (ie so it helps to resolve the first fake call of this function), in other cases, it will work as expected.所以当这个 function 第一次触发时它不会工作(即它有助于解决这个函数的第一次假调用),在其他情况下,它会按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM