added toJson to enum

This commit is contained in:
2026-07-20 14:14:44 +02:00
parent 1b9e096b77
commit 6778b6426f
+12 -5
View File
@@ -9,12 +9,12 @@ abstract class Alarm {
factory Alarm.fromJson(Map<String, dynamic> json) { factory Alarm.fromJson(Map<String, dynamic> json) {
if (json.containsKey('alarmType')) { if (json.containsKey('alarmType')) {
switch (json['alarmType'] as String) { switch (AlarmType.fromJson(json['alarmType'])) {
case 'timeFixed': case AlarmType.timeFixed:
return FixedTimeAlarm.fromJson(json); return FixedTimeAlarm.fromJson(json);
case 'timeRelative': case AlarmType.timeRelative:
return RelativeTimeAlarm.fromJson(json); return RelativeTimeAlarm.fromJson(json);
case 'location': case AlarmType.location:
return LocationAlarm.fromJson(json); return LocationAlarm.fromJson(json);
} }
} }
@@ -33,4 +33,11 @@ abstract class Alarm {
int get hashCode => id.hashCode; 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);
}