再会。我知道我们使用 onSelectNotification 属性来获取当用户在使用颤振本地推送通知包时点击通知时的回调。
Future<void> _initialize() async {
await _configureLocalTimeZone();
AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('@mipmap/ic_launcher');
IOSInitializationSettings initializationSettingsIOS =
IOSInitializationSettings(
onDidReceiveLocalNotification: _onDidReceiveLocalNotification);
InitializationSettings initializationSettings = InitializationSettings(
android: initializationSettingsAndroid, iOS: initializationSettingsIOS);
await _flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: _onSelectNotification); // This is for the callback
}
这是 _onSelectsNotification 函数。
Future _onSelectNotification(String payload) async {
if (payload != null) {
print('notification payload: $payload');
}
BuildContext context;
await Navigator.of(context)
.push(MaterialPageRoute(builder: (BuildContext context) {
return NotificationsView();
})); // ***** This is not working. with no error.
}
我不确定在上下文中使用什么。我认为 NotificationView() 的下一条路径由于上下文值而不起作用。你能帮我解决这个问题吗?我现在使用 GetX 进行状态管理。
谢谢。