我在尝试在iOS上显示onMessage通知时遇到问题,Android正常运行。我发送通知,并且onMessage被触发,但是在Android设备上却没有显示Flushbar。奇怪的是,它在控制台中打印了onMessage,但未在应用程序上显示Flushbar。
@override
void initState() {
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
int idEvent = int.parse(message['data']['idevent']);
String image = message['data']['image'];
Flushbar(
title: message['notification']['title'],
message: message['notification']['body'],
duration: Duration(seconds: 5),
flushbarPosition: FlushbarPosition.TOP,
flushbarStyle: FlushbarStyle.GROUNDED,
onTap: (Flushbar fb) async {
fb.dismiss();
ServiceEvent.fetchEvent(idEvent).then((event) {
if (event != null) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => EventDetailsPage(
event,
fromNotification: true,
),
),
);
} else {
DialogUtility.dialogInfo(
context, "There was an error didn't find event");
}
}).catchError((error) {
DialogUtility.dialogInfo(context, error.toString());
});
},
icon: image != null
? Padding(
padding: const EdgeInsets.symmetric(horizontal: 5.0),
child: Image.network('$image', height: 40, width: 40,),
)
: Padding(
padding: const EdgeInsets.symmetric(horizontal: 5),
child: SvgPicture.asset(
'assets/icons/tarjeta-rocket-entries.svg',
semanticsLabel: 'Acme Logo',
width: 40,
height: 40,
),
),
)..show(buildContext);
},
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
},
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
},
);
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(
sound: true, badge: true, alert: true, provisional: true));
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
});
_firebaseMessaging.getToken().then((String token) {
assert(token != null);
setState(() {
//_homeScreenText = "Push Messaging token: $token";
});
//print('token: '+token);
});
super.initState();
}
答案 0 :(得分:0)
我也遇到过同样的问题,我使用https://pub.dev/packages/flutter_local_notifications插件解决了该问题,或者确保您正确调用了Flushbar API
答案 1 :(得分:0)
只是通知了这个问题。 json在接收onMessage通知时与Android和iOS不同,并且在firebase onMessage上不显示任何异常。
答案 2 :(得分:0)
应用本地通知对我这样起作用
setUpLocalNotification() async {
//Local Notification Configuration--------
var initializationSettingsAndroid = AndroidInitializationSettings('logo');
var initializationSettingsIOS = IOSInitializationSettings();
var initializationSettings = InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: onSelectNotification);
//end local notification
}
以init状态调用该函数,然后检查os类型并显示通知。
if (Platform.isIOS) {
await flutterLocalNotificationsPlugin.show(
0,
message['aps']['alert']['title'],
message['aps']['alert']['body'],
platformChannelSpecifics,
payload: JsonEncoder.withIndent(" ").convert(message),
);
}