AlarmSettings.fromJson constructor

AlarmSettings.fromJson(
  1. Map<String, dynamic> json
)

Constructs an AlarmSettings instance from the given JSON data.

Implementation

factory AlarmSettings.fromJson(Map<String, dynamic> json) {
  // Add support from earlier versions of the plugin.
  final notificationTitle = json['notificationTitle'] as String?;
  final notificationBody = json['notificationBody'] as String?;

  var notificationSettings = NotificationSettings.fromJson(
    json['notificationSettings'] as Map<String, dynamic>,
  );

  if (notificationTitle != null || notificationBody != null) {
    notificationSettings = notificationSettings.copyWith(
      title: notificationTitle ?? notificationSettings.title,
      body: notificationBody ?? notificationSettings.body,
    );
  }

  return AlarmSettings(
    id: json['id'] as int,
    dateTime: DateTime.fromMicrosecondsSinceEpoch(json['dateTime'] as int),
    assetAudioPath: json['assetAudioPath'] as String,
    notificationSettings: notificationSettings,
    loopAudio: json['loopAudio'] as bool,
    vibrate: json['vibrate'] as bool? ?? true,
    volume: json['volume'] as double?,
    fadeDuration: json['fadeDuration'] as double,
    warningNotificationOnKill:
        json['warningNotificationOnKill'] as bool? ?? true,
    androidFullScreenIntent: json['androidFullScreenIntent'] as bool? ?? true,
  );
}