I am a newbie to flutter. I just upgraded a project built for me to flutter 2.0 and I am not certain how to resolve this particular issue. I have googled and found examples. I understand there is improvement here which potentially resolves one of the issues my app was facing. But I do not know enough to know how to adjust this particular section of code because it is more complicated than any examples I can find online. Hoping someone can point me in the right direction.
void initFCMNotification() {
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
mapEntry = message;
String type =
message['Notificationtype'] ?? message['data']['Notificationtype'];
print("notification onMessage $type");
if (type == '5' || type == '11' || type == '3') {
Function reload = context.read<EventsProvider>().reload;
Future.delayed(Duration(seconds: 1), () {
reload(true);
});
} else if (type == '4') {
var notification = getNotification(message);
nav.currentState.push(MaterialPageRoute(
builder: (context) => MeetAgainScreen(notification)));
}
if (type != '11') {
if (Platform.isIOS) {
notiType = message['Notificationtype'];
print('isIOS on message ${message['aps']['alert']['title']}');
if (type == "0") {
reloadData(type, message);
} else {
showSilentNotification(flutterLocalNotificationsPlugin,
title:
"${message['title'] ?? message['aps']['alert']['title'] ?? message['notification']['title'] ?? ''}",
payload: "${message['Notificationtype'] ?? ''}",
body:
"${message['body'] ?? message['aps']['alert']['body'] ?? message['notification']['body'] ?? ''}",
id: 1);
}
} else if (Platform.isAndroid) {
notiType = message['data']['Notificationtype'];
print('Android on message /*${message['data']['body']}*/');
if (type == "0") {
reloadData(type, message);
} else {
showSilentNotification(flutterLocalNotificationsPlugin,
title:
"${message['data']['title'] ?? message['notification']['title'] ?? ''}",
payload: "${message['data']['Notificationtype'] ?? ''}",
body:
"${message['data']['body'] ?? message['notification']['body'] ?? ''}",
id: 1);
}
}
}
Start from version 8.0.0-dev.1, configure()
has been removed in favor of calling specific static methods which return Streams
.
You should use FirebaseMessaging.onMessage()
,FirebaseMessaging.onMessageOpenedApp()
instead.
Here the example
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
...
});
You can find more on this pub's changelog.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With