0

I am developing a flutter app with push notification by firebase and i developing in my Iphone. The notification function is working, but i want to add a redirect function(redirect to special page(route name is "/map").

The function onDidReceiveNotificationResponse will be call when i click the notification message, but it will repeat calling the code inside onDidReceiveNotificationResponse but the redirect function is not work.

The log output

flutter: notification payload:
flutter: onDidReceiveNotificationResponse
flutter: notification payload:
flutter: onDidReceiveNotificationResponse
flutter: notification payload:
flutter: onDidReceiveNotificationResponse

class NotificationService {
  final notificationPlugin = FlutterLocalNotificationsPlugin();
  static final onNotifications = BehaviorSubject<String?>();
  bool _isInitialized = false;
  FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
      FlutterLocalNotificationsPlugin();

  Future<void> initNotification() async {
    print("NotificationService initNotification 1");
    if (_isInitialized) return;

    const initSettingsAndroid =
        AndroidInitializationSettings('@mipmap/ic_launcher');

    const initSettingsIOS = DarwinInitializationSettings(
      requestAlertPermission: true,
      requestBadgePermission: true,
      requestSoundPermission: true,
    );

    void onDidReceiveNotificationResponse(
        NotificationResponse notificationResponse) async {
      final String? payload = notificationResponse.payload;
      if (notificationResponse.payload != null) {
        debugPrint('notification payload: $payload');
        debugPrint('onDidReceiveNotificationResponse');
        AppGlobal.navigatorKey.currentState?.pushNamed('/map');
      }
    }

    const initSetting = InitializationSettings(
        android: initSettingsAndroid, iOS: initSettingsIOS);
    await flutterLocalNotificationsPlugin.initialize(initSetting,
        onDidReceiveNotificationResponse: (notificationResponse) =>
            onDidReceiveNotificationResponse(notificationResponse));
    _isInitialized = !_isInitialized;
  }
0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.