receiveNotificationForeground static method
Future<void>
receiveNotificationForeground(
- Color? backgroundIcon
)
Implementation
static Future<void> receiveNotificationForeground(
Color? backgroundIcon) async {
FirebaseMessaging.onMessage.listen((message) async {
if (InngageProperties.getDebugMode()) {
debugPrint('onMessage ${message.data}');
}
var inappMessage = false;
try {
var data = json.decode(message.data['additional_data']);
inappMessage = data['inapp_message'];
} catch (e) {
debugPrint(e.toString());
}
debugPrint('logx listen $inappMessage');
if (inappMessage) {
try {
const storage = FlutterSecureStorage();
var rawData = message.data['additional_data'];
var data = json.decode(rawData);
inappMessage = data['inapp_message'];
if (inappMessage) {
storage.write(key: "inapp", value: rawData);
}
var inAppModel = InAppModel.fromJson(data);
InngageDialog.showInAppDialog(inAppModel);
} catch (e) {
debugPrint('logx listen $e');
}
} else {
if (Platform.isAndroid) {
AndroidNotificationDetails androidPlatformChannelSpecifics =
AndroidNotificationDetails(
'high_importance_channel', 'your channel name',
channelDescription: 'your channel description',
importance: Importance.max,
priority: Priority.high,
ticker: 'ticker',
color: backgroundIcon ?? Colors.blue);
NotificationDetails platformChannelSpecifics =
NotificationDetails(android: androidPlatformChannelSpecifics);
final titleNotification = message.data['title'] ?? "";
final messageNotification = message.data['message'] ?? "";
if (titleNotification.toString().isNotEmpty &&
messageNotification.toString().isNotEmpty) {
await flutterLocalNotificationsPlugin.show(0, titleNotification,
messageNotification, platformChannelSpecifics,
payload: json.encode(message.data));
}
}
}
});
}