1

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(),
        ),
      ));
    });
  }
}
  • Any solution for this yet? App does not open when it is closed, the code inside setNotificationOpenedHandler executes but app does not come in foreground unless tapped explicitly. – Nandan Wewhare Mar 27 '22 at 09:06
  • @NandanWewhare hi, sorry for late answer. No i could not find any solution. Issue is coming from MIUI ( XIAOMI). I leaved it as it is. waiting solution form developer. I have no time now for this. meanwhile, if you could find any solution share please and so i. thanks – Vakhtang Zubiashvili VakhoZuba May 06 '22 at 07:53

0 Answers0