方法'onSelectNotifications'不是使用颤振本地通知插件定义的



在flatter_local_notification 12.0.2 中

onSelectNotification参数不再存在。那么,有什么替代方案呢。这样我们就可以在点击通知时处理回调。

您可以stream通知

import 'package:rxdart/rxdart.dart';
...
// use this 
class MyNotifManager {
static final onNotifications = BehaviorSubject<String?>();
...
// then add the payload to your local notification
// exampel for  the foreground notif
onDidReceiveNotificationResponse: (payload) async {
onNotifications.add(payload.payload); // add payload to the stream
},

然后处理回调:

Future<void> listenNotification() async =>
MyNotifManager.onNotifications.stream.listen(onClickNotification);

点击后的行动

void onClickNotification(String? payload) {
Navigator.push();
}

调用initState 上的流

@override
void initState() {
super.initState();
MyNotifManager.init();
listenNotification();
}

使用此方法,您将能够在单击通知时处理calback。

插件初始化时有onDidReceiveNotificationResponse回调。

_plugin.initialize(
initializationSettings,
onDidReceiveNotificationResponse: (details) {
// Click Notification Event Here
},
);

如果您在应用程序终止时单击通知,

_plugin.getNotificationAppLaunchDetails().then((value) {
// Click Notification Event Here
});

最新更新