I want to enter in a specific page when tapped on the notification banner the app is in foreground. Right now when notification appears my app automatically navigate to NotificationPage. I'm developing an android and iOS mobile app with Flutter.
Already added in manifest file:
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="high_importance_channel" />
I'm useing this method below to show the notification banner inside MyApp() file:
void showFlutterNotification(RemoteMessage message) {
RemoteNotification? notification = message.notification;
AndroidNotification? android = message.notification?.android;
if (notification != null && android != null) {
flutterLocalNotificationsPlugin.show(
notification.hashCode,
notification.title,
notification.body,
NotificationDetails(
android: AndroidNotificationDetails(
channel.id,
channel.name,
channelDescription: channel.description,
icon: 'launch_background',
),
),
);
}
}
and this method to handle received notification:
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print(message.data.toString());
showFlutterNotification(message);
if (message.data['type'] == 'chat') {
Navigator.pushNamed(
context,
'/message',
arguments: MessageArguments(message, true),
);
}
});
In my main:
routes: {
'/':PaginaDopoLogin(),
'/message': (context) => NotificationPage(),
}