'Flutter OneSignal does not opens app when click on notification

I have Flutter app, which works fine with OneSignal plugin, but i have one issue, when click on notification i can not open app if app is closed or runs background, but when forground it opens notification without issue. I want to open app when notification comes, and i wclick on it.

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  static const String oneSignalAppId = "XXXXXX-XXXXX-XXXXXXX-XXXXXX-XXXXX";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Manchester United"),
        elevation: 0,
      ),
      backgroundColor: Colors.red[200],
      body: const WebView(
        initialUrl: 'https://manchester-united.football/',
        javascriptMode: JavascriptMode.unrestricted,
      ),
    );
  }

  Future<void> initPlatformState() async {
    OneSignal.shared.setAppId(
      oneSignalAppId,
    ); //OneSignal.shared.setInFocusDisplayType(OSNotificationDisplayType.notification);
    OneSignal.shared
        .setNotificationOpenedHandler((OSNotificationOpenedResult result) {
      var data = result.notification.additionalData;

      globals.appNavigator?.currentState?.push(MaterialPageRoute(
        builder: (context) => SecondPage(
          postId: data!["myappurl"].toString(),
        ),
      ));
    });
  }
}


Sources

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

Source: Stack Overflow

Solution Source