any tips on how to show the images I record in the firebase console in the push notification? They are working but when I send with an image it does not appear in the notification. I'm using firebase_message and flutter_local_notifications.
When I send the notification it appears, but the image does not. Remembering that the image I put the URl in the creation of the notification in the firebaseConsole
FirebaseConfiguration:
class FireBaseNotifications {
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
final LocalNotifications _localNotifications;
FireBaseNotifications._internal(this._localNotifications);
static final FireBaseNotifications _singleton =
FireBaseNotifications._internal(LocalNotifications());
factory FireBaseNotifications() => _singleton;
Future<void> initializeFirebasePushServices() async {
await FirebaseMessaging.instance
.setForegroundNotificationPresentationOptions(
badge: true, sound: true, alert: true);
FirebaseMessaging.onMessage.listen(
(push) {
RemoteNotification? notification = push.notification;
AndroidNotification? androidNotification = push.notification?.android;
AppleNotification? iosNotification = push.notification?.apple;
if (notification != null && androidNotification != null) {
_localNotifications.androidNotifications(
notification: notification,
androidNotification: androidNotification,
);
}
if (notification != null && iosNotification != null) {
_localNotifications.iosNotifications(
notification: notification,
iosNotification: iosNotification,
);
}
},
);
if (Platform.isIOS) {
FirebaseMessaging.onMessageOpenedApp.listen(
(route) {
if (route.data['goTo'] != null) {
navigatorKey.currentState?.pushNamed(route.data['goTo']);
}
},
);
}
if (Platform.isAndroid) {
FirebaseMessaging.onMessageOpenedApp.listen(
(route) {
if (route.data['goTo'] != null) {
navigatorKey.currentState?.pushNamed(route.data['goTo']);
}
},
);
}
}
Future<void> getTokenFirebase() async =>
debugPrint(await FirebaseMessaging.instance.getToken());
}
Flutter local notifications:
class LocalNotifications {
late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
late AndroidNotificationChannel androidNotificationChannel;
LocalNotifications() {
androidNotificationChannel = const AndroidNotificationChannel(
'high_importance_channel',
'high_importance_notifications',
description: 'channel used for very important notifications',
importance: Importance.max,
);
_androidConfig().then(
(value) {
flutterLocalNotificationsPlugin = value;
initializeNotifications();
},
);
_iosConfig().then((value) {
flutterLocalNotificationsPlugin = value;
initializeNotifications();
});
}
Future<FlutterLocalNotificationsPlugin> _androidConfig() async {
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(androidNotificationChannel);
return flutterLocalNotificationsPlugin;
}
Future<FlutterLocalNotificationsPlugin> _iosConfig() async {
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
return flutterLocalNotificationsPlugin;
}
void initializeNotifications() {
const android = AndroidInitializationSettings('@mipmap/ic_launcher');
const ios = IOSInitializationSettings(
// onDidReceiveLocalNotification: ,
requestSoundPermission: false,
requestBadgePermission: false,
requestAlertPermission: false,
);
flutterLocalNotificationsPlugin
.initialize(const InitializationSettings(android: android, iOS: ios));
}
void androidNotifications({
required RemoteNotification notification,
required AndroidNotification? androidNotification,
}) {
flutterLocalNotificationsPlugin.show(
notification.hashCode,
notification.title,
notification.body,
NotificationDetails(
android: AndroidNotificationDetails(
androidNotificationChannel.id, androidNotificationChannel.name,
channelDescription: androidNotificationChannel.description,
icon: androidNotification?.smallIcon),
),
);
}
void iosNotifications({
required RemoteNotification notification,
required AppleNotification? iosNotification,
}) {
flutterLocalNotificationsPlugin.show(
notification.hashCode,
notification.title,
notification.body,
const NotificationDetails(
iOS: IOSNotificationDetails(),
),
);
}
}