added toJson to enum
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user