diff --git a/lib/model/alarm/alarm.dart b/lib/model/alarm/alarm.dart index ebe981f..7d3e113 100644 --- a/lib/model/alarm/alarm.dart +++ b/lib/model/alarm/alarm.dart @@ -9,12 +9,12 @@ abstract class Alarm { factory Alarm.fromJson(Map json) { if (json.containsKey('alarmType')) { - switch (json['alarmType'] as String) { - case 'timeFixed': + switch (AlarmType.fromJson(json['alarmType'])) { + case AlarmType.timeFixed: return FixedTimeAlarm.fromJson(json); - case 'timeRelative': + case AlarmType.timeRelative: return RelativeTimeAlarm.fromJson(json); - case 'location': + case AlarmType.location: return LocationAlarm.fromJson(json); } } @@ -33,4 +33,11 @@ abstract class Alarm { int get hashCode => id.hashCode; } -enum AlarmType { timeFixed, timeRelative, location } +enum AlarmType { + timeFixed, + timeRelative, + location; + + String toJson() => name; + static AlarmType fromJson(String json) => values.byName(json); +}