extended logic of alarm interface
This commit is contained in:
@@ -1,3 +1,29 @@
|
||||
import 'location_alarm.dart';
|
||||
import 'time_alarm.dart';
|
||||
|
||||
abstract class Alarm {
|
||||
String get id;
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
factory Alarm.fromJson(Map<String, dynamic> json) {
|
||||
if (json.containsKey('triggerAt')) {
|
||||
return TimeAlarm.fromJson(json);
|
||||
}
|
||||
|
||||
if (json.containsKey('location')) {
|
||||
return LocationAlarm.fromJson(json);
|
||||
}
|
||||
|
||||
throw ArgumentError('Unknown alarm type');
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (other is! Alarm) return false;
|
||||
|
||||
return hashCode == other.hashCode;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => id.hashCode;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ class LocationAlarm implements Alarm {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
|
||||
@@ -15,6 +15,7 @@ class TimeAlarm implements Alarm {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return {'id': id, 'triggerAt': triggerAt.toIso8601String()};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user