extended logic of alarm interface

This commit is contained in:
2026-06-18 19:01:00 +02:00
parent c5fafc2053
commit f9642b0230
3 changed files with 28 additions and 0 deletions
+26
View File
@@ -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;
}
+1
View File
@@ -23,6 +23,7 @@ class LocationAlarm implements Alarm {
);
}
@override
Map<String, dynamic> toJson() {
return {
'id': id,
+1
View File
@@ -15,6 +15,7 @@ class TimeAlarm implements Alarm {
);
}
@override
Map<String, dynamic> toJson() {
return {'id': id, 'triggerAt': triggerAt.toIso8601String()};
}