createNotificationFromJsonData method
Creates a new notification based on a map similar to the map produced by toMap method
Implementation
@override
Future<bool> createNotificationFromJsonData(
Map<String, dynamic> mapData) async {
try {
if (mapData[NOTIFICATION_CONTENT] is String) {
mapData[NOTIFICATION_CONTENT] =
json.decode(mapData[NOTIFICATION_CONTENT]);
}
if (mapData[NOTIFICATION_SCHEDULE] is String) {
mapData[NOTIFICATION_SCHEDULE] =
json.decode(mapData[NOTIFICATION_SCHEDULE]);
}
if (mapData[NOTIFICATION_BUTTONS] is String) {
mapData[NOTIFICATION_BUTTONS] =
json.decode(mapData[NOTIFICATION_BUTTONS]);
}
// Invalid Notification
NotificationModel? notificationModel =
NotificationModel().fromMap(mapData);
if (notificationModel == null) {
throw Exception('Notification map data is invalid');
}
return createNotification(
content: notificationModel.content!,
schedule: notificationModel.schedule,
actionButtons: notificationModel.actionButtons);
} catch (e) {
return false;
}
}