addFcmActionToDatabase function
- SharedDatabase database,
- RemoteMessage message
Saves the action from a Firebase Cloud Messaging message to the local database
Implementation
Future<void> addFcmActionToDatabase(
SharedDatabase database,
RemoteMessage message,
) async {
final notification = fcmToAppNotification(message);
if (notification == null) {
if (kDebugMode) {
print('Action $message could not be saved.');
}
return;
}
final payload = notification.action != null
? jsonEncode(notification.action!.toJson())
: null;
if (payload == null) {
if (kDebugMode) {
print('Action $message could not be saved.');
}
return;
}
await database.into(database.notificationActions).insert(
NotificationActionsCompanion.insert(
notificationId: notification.id,
payload: payload,
),
);
}