refactored project structure
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import 'fixed_time_alarm.dart';
|
||||
import 'location_alarm.dart';
|
||||
import 'relative_time_alarm.dart';
|
||||
|
||||
abstract class Alarm {
|
||||
String get id;
|
||||
String get taskId;
|
||||
AlarmType get alarmType;
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
factory Alarm.fromJson(Map<String, dynamic> json) {
|
||||
if (json.containsKey('alarmType')) {
|
||||
switch (json['alarmType'] as String) {
|
||||
case 'timeFixed':
|
||||
return FixedTimeAlarm.fromJson(json);
|
||||
case 'timeRelative':
|
||||
return RelativeTimeAlarm.fromJson(json);
|
||||
case '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;
|
||||
}
|
||||
|
||||
enum AlarmType { timeFixed, timeRelative, location }
|
||||
Reference in New Issue
Block a user