Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
944 B
1
Indexable
Never

Future<void> setupInteractedMessage() async
{
    FirebaseMessaging.instance.getInitialMessage().then((RemoteMessage? initialMessage) {
        if (initialMessage != null) {
            _handleMessage(initialMessage);
        }
    });

    FirebaseMessaging.onMessageOpenedApp.listen(_handleMessage);

    FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
        RemoteNotification? notification = message.notification;
        if(notification != null)
        {
            print(message.data);
        }
        LocalNotificationService.displayLocalNotification(message);
    });

  }


  void _handleMessage(RemoteMessage message)
  {
      print(message.data)
      Navigator.push(context,MaterialPageRoute(builder: (context) => Screen2(messageData: message.data),),);
  }


  @override
  void initState() {
      super.initState();
      LocalNotificationService.initialize(context);
      setupInteractedMessage();
  }