Вам нужно будет зарегистрировать глобальный дескриптор Navigator в основной платформе приложения - тогда вы сможете использовать его в своих обработчиках уведомлений ..
Итак - в нашем приложении в нашем основном приложении у нас есть:
// Initialize our global NavigatorKey
globals.navigatorKey = GlobalKey<NavigatorState>();
...
return MaterialApp(
title: 'MissionMode Mobile',
theme: theme,
initialRoute: _initialRoute,
onGenerateRoute: globals.router.generator,
navigatorKey: globals.navigatorKey,
);
Ключом является navigatorKey: часть и сохранение его где-то, куда вы можете получить доступ куда-то еще ..
Затем в вашем обработчике:
OneSignal.shared.setNotificationOpenedHandler (_handleNotificationOpened);...
// What to do when the user opens/taps on a notification
void _handleNotificationOpened(OSNotificationOpenedResult result) {
print('[notification_service - _handleNotificationOpened()');
print(
"Opened notification: ${result.notification.jsonRepresentation().replaceAll("\\n", "\n")}");
// Since the only thing we can get current are new Alerts -- go to the Alert screen
globals.navigatorKey.currentState.pushNamed('/home');
}
Это должно сработать - все равно для нас :)