31 lines
619 B
Dart
31 lines
619 B
Dart
import 'location_alarm.dart';
|
|
import 'time_alarm.dart';
|
|
|
|
abstract class Alarm {
|
|
String get id;
|
|
String get taskId;
|
|
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 => taskId.hashCode;
|
|
}
|