不,我不是在这里询问 Firebase Cloud Messaging 通知,而是纯粹使用来自这里的本地通知包颤动本地通知
我希望如果我的用户单击通知,那么它将被定向到某个页面。怎么做 ?
目前我的代码是这样的
class LocalNotificationService {
late FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin;
LocalNotificationService._privateConstructor() {
_init();
}
static final LocalNotificationService _instance = LocalNotificationService._privateConstructor();
static LocalNotificationService get instance => _instance; // singleton access
void _init() {
_flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
_initializePlatformSpecifics();
}
Future<void> _initializePlatformSpecifics() async {
var androidInitializationSettings = AndroidInitializationSettings("app_notification_icon");
var iOSInitializationSettings = IOSInitializationSettings(
requestAlertPermission: true,
requestBadgePermission: true,
requestSoundPermission: true,
onDidReceiveLocalNotification: (id, title, body, payload) async {
// do something if notification is clicked
},
);
final initializationSettings = InitializationSettings(
android: androidInitializationSettings,
iOS: iOSInitializationSettings,
);
await _flutterLocalNotificationsPlugin.initialize(initializationSettings);
}
void showSimpleNotification({
required String title,
required String body,
required NotificationType notificationType,
}) async {
var android = _setAndroidNotificationDetails(notificationType);
var ios = IOSNotificationDetails();
var notificationDetails = new NotificationDetails(android: android, iOS: ios);
await _flutterLocalNotificationsPlugin.show(
1, // only need to show one notification in the notification tray, so it is ok if we use the Notification ID
title,
body,
notificationDetails,
);
}
}