'Parse additional data in push notification by OneSingal by flutter

Please help me for this case. I implement feature - push notification by OneSignal.
My situation as belows:

Android devices:

  • Receive notification:
    • App close: open push, navigate to specific Page I set. OK
    • App open, run in background: open push, navigate to specific Page I set. OK

IOS devices:

  • Receive notification:
    • App close: open push, only open app, not go to specific page. NOT GOOD
    • App open, run in background: open push, navigate to specific Page I set. OK

My snippet code:

HomePage.dart

void initState() {
    _bloc = getCurrentBloc<HomeBloc>();
    OneSignalWapper.handleClickNotification(context);
//    OneSignalWapper.handleReceiveNotification(context);
    super.initState();
}

OneSignalWapper.dart

  static void handleClickNotification(BuildContext context) {
    OneSignal.shared
        .setNotificationOpenedHandler((OSNotificationOpenedResult result) async {
      try {
        var postId = await result.notification.payload.additionalData["post_id"];
        Navigator.of(context).push(MaterialPageRoute(
            builder: (context) => PostDetailsScreen.newInstance('$postId')));
      } catch (e, stacktrace) {
        log(e);
      }
    });
  }

Most of test cases are worked already. There is only one case: IOS, close APP (NOT GOOD case above).
How can I fix it. Please give some advices.
Thanks a lot!!!



Solution 1:[1]

final GlobalKey navigatorKey = new GlobalKey();

    OneSignal.shared.setNotificationOpenedHandler((OSNotificationOpenedResult result) {
  print('B?LD?R?M AÇILDI ??LEY?C? ?LE ÇA?RILANMI?TIR: ${result}');

  navigatorKey.currentState!.push(
    MaterialPageRoute(
      builder: (context) => YourPage(),
    ),
  );


});

MaterialApp navigatorKey: navigatorKey,

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Baris