当应用程序处于前台或后台时,flutter_local_notifications 工作正常
但是当应用程序终止时
onSelectNotification 没有按预期工作,而是打开应用程序
static void initializeLocalNotification() async {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('ic_launcher');
final IOSInitializationSettings initializationSettingsIOS =
IOSInitializationSettings(
requestSoundPermission: false,
requestBadgePermission: false,
requestAlertPermission: false,
);
final InitializationSettings initializationSettings =
InitializationSettings(
android: initializationSettingsAndroid,
iOS: initializationSettingsIOS,
);
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: (String payload) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var res = await prefs.setString(kNotificationPayLoad, payload);
// navigatorKey.currentState
// .push(MaterialPageRoute(builder: (_) => LoginScreen()));
// navigatorKey.currentState.pop();
});
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin>()
?.requestPermissions(
alert: true,
badge: true,
sound: true,
);
}