refactored project structure

This commit is contained in:
2026-07-17 17:08:31 +02:00
parent 3ceb0896a4
commit 02469faf52
23 changed files with 33 additions and 33 deletions
+37
View File
@@ -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 }
+38
View File
@@ -0,0 +1,38 @@
import 'alarm.dart';
class FixedTimeAlarm implements Alarm {
@override
final String id;
@override
final String taskId;
final DateTime triggerAt;
@override
final AlarmType alarmType;
const FixedTimeAlarm({
required this.id,
required this.taskId,
required this.triggerAt,
}) : alarmType = AlarmType.timeFixed;
factory FixedTimeAlarm.fromJson(Map<String, dynamic> json) {
return FixedTimeAlarm(
id: json['id'] as String,
taskId: json['taskId'] as String,
triggerAt: DateTime.parse(json['triggerAt'] as String),
);
}
@override
Map<String, dynamic> toJson() {
return {
'id': id,
'taskId': taskId,
'triggerAt': triggerAt.toIso8601String(),
'alarmType': alarmType,
};
}
}
+44
View File
@@ -0,0 +1,44 @@
import 'alarm.dart';
import '../location.dart';
class LocationAlarm implements Alarm {
@override
final String id;
@override
final String taskId;
final Location location;
final int radiusMeters;
@override
final AlarmType alarmType;
const LocationAlarm({
required this.id,
required this.taskId,
required this.location,
required this.radiusMeters,
}) : alarmType = AlarmType.location;
factory LocationAlarm.fromJson(Map<String, dynamic> json) {
return LocationAlarm(
id: json['id'] as String,
taskId: json['taskId'] as String,
location: Location.fromJson(json['location'] as Map<String, dynamic>),
radiusMeters: json['radiusMeters'] as int,
);
}
@override
Map<String, dynamic> toJson() {
return {
'id': id,
'taskId': taskId,
'location': location.toJson(),
'radiusMeters': radiusMeters,
'alarmType': alarmType,
};
}
}
+38
View File
@@ -0,0 +1,38 @@
import 'alarm.dart';
class RelativeTimeAlarm implements Alarm {
@override
final String id;
@override
final String taskId;
final DateTime triggerAt;
@override
final AlarmType alarmType;
const RelativeTimeAlarm({
required this.id,
required this.taskId,
required this.triggerAt,
}) : alarmType = AlarmType.timeRelative;
factory RelativeTimeAlarm.fromJson(Map<String, dynamic> json) {
return RelativeTimeAlarm(
id: json['id'] as String,
taskId: json['taskId'] as String,
triggerAt: DateTime.parse(json['triggerAt'] as String),
);
}
@override
Map<String, dynamic> toJson() {
return {
'id': id,
'taskId': taskId,
'triggerAt': triggerAt.toIso8601String(),
'alarmType': alarmType,
};
}
}