pushy / pushy-flutter

The official Pushy SDK for Flutter apps.
Apache License 2.0
21 stars 19 forks source link

A blank screen appears when app is killed and user taps on a notification #52

Closed shahpasandar closed 1 year ago

shahpasandar commented 1 year ago

When user taps on a push notification in killed state of the app then it will open a white blank screen and app stucks on this screen. When app is in background, it will navigate the user to the desire screen.

main.dart:

//Top-level pushy background notification listener
@pragma('vm:entry-point')
void backgroundNotificationListener(Map<String, dynamic> data) {
  final result = NotificationData.fromJson(data);

  try {
    if (!kIsWeb) {
      PushNotification().showNotification(data: result);
    } else {
      Pushy.notify(result.title ?? "", result.body ?? "", data);
    }
  } catch (e) {
    Pushy.notify(result.title ?? "", result.body ?? "", data);
  }

  Pushy.clearBadge();
}

Future main() async {
  await _initApp();
  runApp(Application());
}
shahpasandar commented 1 year ago

I'd tried to call register while initializing pushy like this (following method was called in the main.dart):

    // Start the Pushy service
    Pushy.listen();

    // Set custom notification icon (Android)
    Pushy.setNotificationIcon('ic_notify');

    // Register the device for push notifications
    String deviceToken = await Pushy.register();

And then somewhere else in the app life cycle I'd called Pushy.register() again. I found that the first call of the Pushy.register() in the main.dart caused this issue.

pushy commented 1 year ago

Hi @shahpasandar, Thanks for letting us know how you managed to resolve the issue, and glad you were able to find the root cause.