Files
tasks/lib/model/alarm/alarm.dart
T
2026-07-20 14:14:44 +02:00

44 lines
1000 B
Dart

import 'fixed_time_alarm.dart';
import 'location_alarm.dart';
import 'relative_time_alarm.dart';
abstract class Alarm {
String get id;
AlarmType get alarmType;
Map<String, dynamic> toJson();
factory Alarm.fromJson(Map<String, dynamic> json) {
if (json.containsKey('alarmType')) {
switch (AlarmType.fromJson(json['alarmType'])) {
case AlarmType.timeFixed:
return FixedTimeAlarm.fromJson(json);
case AlarmType.timeRelative:
return RelativeTimeAlarm.fromJson(json);
case AlarmType.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;
}
enum AlarmType {
timeFixed,
timeRelative,
location;
String toJson() => name;
static AlarmType fromJson(String json) => values.byName(json);
}