如果应用程序关闭时 onSelectNotification Navigator 无法正常工作
onSelectNotification Navigator not working if app closed flutter
onSelectNotification when good when app open
Future<void> onSelectNotification(String payload) async {
Category category = Category();
category.id = notification.idNew;
category.email = notification.mainphoto;
category.since = notification.since;
category.name = notification.title;
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FourthRoute(
category: category,
)));
}
当打开并点击通知时,它会转到 FourthRoute
但关闭时只是打开应用程序导航器无法正常工作
ios 和 android 处的问题
我想在 onSelectNotification 中使用 SharedPreferences 来保存密钥
稍后查看
但我读到当应用程序关闭时飞镖不工作
我联系插件支持
Future<void> main() async {
// needed if you intend to initialize in the `main` function
WidgetsFlutterBinding.ensureInitialized();
notificationAppLaunchDetails =
await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();
var initializationSettingsAndroid = AndroidInitializationSettings('app_icon');
// Note: permissions aren't requested here just to demonstrate that can be done later using the `requestPermissions()` method
// of the `IOSFlutterLocalNotificationsPlugin` class
var initializationSettingsIOS = IOSInitializationSettings(
requestAlertPermission: false,
requestBadgePermission: false,
requestSoundPermission: false,
onDidReceiveLocalNotification:
(int id, String title, String body, String payload) async {
didReceiveLocalNotificationSubject.add(ReceivedNotification(
id: id, title: title, body: body, payload: payload));
});
var initializationSettings = InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: (String payload) async {
if (payload != null) {
debugPrint('notification payload: ' + payload);
}
selectNotificationSubject.add(payload);
});
runApp(
MaterialApp(
home: HomePage(),
),
);
}
Navigator 必须作为子组件包装在 MaterialApp 小部件中,否则,您必须使用 navKey 来引用您的 materialApp。
1. final navKey = new GlobalKey<NavigatorState>();
2. MaterialAPP(title: 'title', ..., navigatorKey: navKey)
3. And then use the key to route to your widget,
navKey.currentState.push(MaterialPageRoute(builder: (context) => NewRoute()));
var details = await NotificationService()
.flutterLocalNotificationsPlugin
.getNotificationAppLaunchDetails();
if (details.didNotificationLaunchApp) {
print(details.payload);
}
在应用程序入口中使用此代码可获得点击有效负载的通知
onSelectNotification when good when app open
Future<void> onSelectNotification(String payload) async {
Category category = Category();
category.id = notification.idNew;
category.email = notification.mainphoto;
category.since = notification.since;
category.name = notification.title;
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FourthRoute(
category: category,
)));
}
当打开并点击通知时,它会转到 FourthRoute
但关闭时只是打开应用程序导航器无法正常工作
ios 和 android 处的问题
我想在 onSelectNotification 中使用 SharedPreferences 来保存密钥 稍后查看
但我读到当应用程序关闭时飞镖不工作
我联系插件支持
Future<void> main() async {
// needed if you intend to initialize in the `main` function
WidgetsFlutterBinding.ensureInitialized();
notificationAppLaunchDetails =
await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();
var initializationSettingsAndroid = AndroidInitializationSettings('app_icon');
// Note: permissions aren't requested here just to demonstrate that can be done later using the `requestPermissions()` method
// of the `IOSFlutterLocalNotificationsPlugin` class
var initializationSettingsIOS = IOSInitializationSettings(
requestAlertPermission: false,
requestBadgePermission: false,
requestSoundPermission: false,
onDidReceiveLocalNotification:
(int id, String title, String body, String payload) async {
didReceiveLocalNotificationSubject.add(ReceivedNotification(
id: id, title: title, body: body, payload: payload));
});
var initializationSettings = InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: (String payload) async {
if (payload != null) {
debugPrint('notification payload: ' + payload);
}
selectNotificationSubject.add(payload);
});
runApp(
MaterialApp(
home: HomePage(),
),
);
}
Navigator 必须作为子组件包装在 MaterialApp 小部件中,否则,您必须使用 navKey 来引用您的 materialApp。
1. final navKey = new GlobalKey<NavigatorState>();
2. MaterialAPP(title: 'title', ..., navigatorKey: navKey)
3. And then use the key to route to your widget,
navKey.currentState.push(MaterialPageRoute(builder: (context) => NewRoute()));
var details = await NotificationService()
.flutterLocalNotificationsPlugin
.getNotificationAppLaunchDetails();
if (details.didNotificationLaunchApp) {
print(details.payload);
}
在应用程序入口中使用此代码可获得点击有效负载的通知