Compare commits
4
Commits
7fed7bfe16
...
8113ce9c22
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8113ce9c22 | ||
|
|
06de421ee2 | ||
|
|
e7d6735d27 | ||
|
|
79cae9570d |
@@ -4,7 +4,6 @@ import 'relative_time_alarm.dart';
|
|||||||
|
|
||||||
abstract class Alarm {
|
abstract class Alarm {
|
||||||
String get id;
|
String get id;
|
||||||
String get taskId;
|
|
||||||
AlarmType get alarmType;
|
AlarmType get alarmType;
|
||||||
Map<String, dynamic> toJson();
|
Map<String, dynamic> toJson();
|
||||||
|
|
||||||
@@ -31,7 +30,7 @@ abstract class Alarm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode => taskId.hashCode;
|
int get hashCode => id.hashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum AlarmType { timeFixed, timeRelative, location }
|
enum AlarmType { timeFixed, timeRelative, location }
|
||||||
|
|||||||
@@ -4,24 +4,17 @@ class FixedTimeAlarm implements Alarm {
|
|||||||
@override
|
@override
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
@override
|
|
||||||
final String taskId;
|
|
||||||
|
|
||||||
final DateTime triggerAt;
|
final DateTime triggerAt;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final AlarmType alarmType;
|
final AlarmType alarmType;
|
||||||
|
|
||||||
const FixedTimeAlarm({
|
const FixedTimeAlarm({required this.id, required this.triggerAt})
|
||||||
required this.id,
|
: alarmType = AlarmType.timeFixed;
|
||||||
required this.taskId,
|
|
||||||
required this.triggerAt,
|
|
||||||
}) : alarmType = AlarmType.timeFixed;
|
|
||||||
|
|
||||||
factory FixedTimeAlarm.fromJson(Map<String, dynamic> json) {
|
factory FixedTimeAlarm.fromJson(Map<String, dynamic> json) {
|
||||||
return FixedTimeAlarm(
|
return FixedTimeAlarm(
|
||||||
id: json['id'] as String,
|
id: json['id'] as String,
|
||||||
taskId: json['taskId'] as String,
|
|
||||||
triggerAt: DateTime.parse(json['triggerAt'] as String),
|
triggerAt: DateTime.parse(json['triggerAt'] as String),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -30,7 +23,6 @@ class FixedTimeAlarm implements Alarm {
|
|||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
return {
|
return {
|
||||||
'id': id,
|
'id': id,
|
||||||
'taskId': taskId,
|
|
||||||
'triggerAt': triggerAt.toIso8601String(),
|
'triggerAt': triggerAt.toIso8601String(),
|
||||||
'alarmType': alarmType,
|
'alarmType': alarmType,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,9 +5,6 @@ class LocationAlarm implements Alarm {
|
|||||||
@override
|
@override
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
@override
|
|
||||||
final String taskId;
|
|
||||||
|
|
||||||
final Location location;
|
final Location location;
|
||||||
|
|
||||||
final int radiusMeters;
|
final int radiusMeters;
|
||||||
@@ -17,7 +14,6 @@ class LocationAlarm implements Alarm {
|
|||||||
|
|
||||||
const LocationAlarm({
|
const LocationAlarm({
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.taskId,
|
|
||||||
required this.location,
|
required this.location,
|
||||||
required this.radiusMeters,
|
required this.radiusMeters,
|
||||||
}) : alarmType = AlarmType.location;
|
}) : alarmType = AlarmType.location;
|
||||||
@@ -25,7 +21,6 @@ class LocationAlarm implements Alarm {
|
|||||||
factory LocationAlarm.fromJson(Map<String, dynamic> json) {
|
factory LocationAlarm.fromJson(Map<String, dynamic> json) {
|
||||||
return LocationAlarm(
|
return LocationAlarm(
|
||||||
id: json['id'] as String,
|
id: json['id'] as String,
|
||||||
taskId: json['taskId'] as String,
|
|
||||||
location: Location.fromJson(json['location'] as Map<String, dynamic>),
|
location: Location.fromJson(json['location'] as Map<String, dynamic>),
|
||||||
radiusMeters: json['radiusMeters'] as int,
|
radiusMeters: json['radiusMeters'] as int,
|
||||||
);
|
);
|
||||||
@@ -35,7 +30,6 @@ class LocationAlarm implements Alarm {
|
|||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
return {
|
return {
|
||||||
'id': id,
|
'id': id,
|
||||||
'taskId': taskId,
|
|
||||||
'location': location.toJson(),
|
'location': location.toJson(),
|
||||||
'radiusMeters': radiusMeters,
|
'radiusMeters': radiusMeters,
|
||||||
'alarmType': alarmType,
|
'alarmType': alarmType,
|
||||||
|
|||||||
@@ -4,24 +4,17 @@ class RelativeTimeAlarm implements Alarm {
|
|||||||
@override
|
@override
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
@override
|
|
||||||
final String taskId;
|
|
||||||
|
|
||||||
final DateTime triggerAt;
|
final DateTime triggerAt;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final AlarmType alarmType;
|
final AlarmType alarmType;
|
||||||
|
|
||||||
const RelativeTimeAlarm({
|
const RelativeTimeAlarm({required this.id, required this.triggerAt})
|
||||||
required this.id,
|
: alarmType = AlarmType.timeRelative;
|
||||||
required this.taskId,
|
|
||||||
required this.triggerAt,
|
|
||||||
}) : alarmType = AlarmType.timeRelative;
|
|
||||||
|
|
||||||
factory RelativeTimeAlarm.fromJson(Map<String, dynamic> json) {
|
factory RelativeTimeAlarm.fromJson(Map<String, dynamic> json) {
|
||||||
return RelativeTimeAlarm(
|
return RelativeTimeAlarm(
|
||||||
id: json['id'] as String,
|
id: json['id'] as String,
|
||||||
taskId: json['taskId'] as String,
|
|
||||||
triggerAt: DateTime.parse(json['triggerAt'] as String),
|
triggerAt: DateTime.parse(json['triggerAt'] as String),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -30,7 +23,6 @@ class RelativeTimeAlarm implements Alarm {
|
|||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
return {
|
return {
|
||||||
'id': id,
|
'id': id,
|
||||||
'taskId': taskId,
|
|
||||||
'triggerAt': triggerAt.toIso8601String(),
|
'triggerAt': triggerAt.toIso8601String(),
|
||||||
'alarmType': alarmType,
|
'alarmType': alarmType,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,17 @@
|
|||||||
import '../alarm/alarm.dart';
|
import '../alarm/alarm.dart';
|
||||||
|
import '../alarm/fixed_time_alarm.dart';
|
||||||
import 'create_alarm_request.dart';
|
import 'create_alarm_request.dart';
|
||||||
|
|
||||||
class CreateFixedTimeAlarmRequest extends CreateAlarmRequest {
|
class CreateFixedTimeAlarmRequest extends CreateAlarmRequest {
|
||||||
final DateTime? triggerAt;
|
final DateTime? triggerAt;
|
||||||
|
|
||||||
CreateFixedTimeAlarmRequest({this.triggerAt})
|
const CreateFixedTimeAlarmRequest({this.triggerAt})
|
||||||
: super(alarmType: AlarmType.timeFixed);
|
: super(alarmType: AlarmType.timeFixed);
|
||||||
|
|
||||||
|
CreateFixedTimeAlarmRequest.fromAlarm(FixedTimeAlarm alarm)
|
||||||
|
: triggerAt = alarm.triggerAt,
|
||||||
|
super(alarmType: AlarmType.timeFixed);
|
||||||
|
|
||||||
|
FixedTimeAlarm toFixedTimeAlarm(String id) =>
|
||||||
|
FixedTimeAlarm(id: id, triggerAt: triggerAt!);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import '../alarm/alarm.dart' show AlarmType;
|
import '../alarm/alarm.dart' show AlarmType;
|
||||||
|
import '../alarm/location_alarm.dart';
|
||||||
import '../location.dart';
|
import '../location.dart';
|
||||||
import 'create_alarm_request.dart';
|
import 'create_alarm_request.dart';
|
||||||
|
|
||||||
@@ -9,4 +10,12 @@ class CreateLocationAlarmRequest extends CreateAlarmRequest {
|
|||||||
|
|
||||||
const CreateLocationAlarmRequest({this.location, this.radiusMeters})
|
const CreateLocationAlarmRequest({this.location, this.radiusMeters})
|
||||||
: super(alarmType: AlarmType.location);
|
: super(alarmType: AlarmType.location);
|
||||||
|
|
||||||
|
CreateLocationAlarmRequest.fromAlarm(LocationAlarm alarm)
|
||||||
|
: location = alarm.location,
|
||||||
|
radiusMeters = alarm.radiusMeters,
|
||||||
|
super(alarmType: AlarmType.location);
|
||||||
|
|
||||||
|
LocationAlarm toLocationAlarm(String id) =>
|
||||||
|
LocationAlarm(id: id, location: location!, radiusMeters: radiusMeters!);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,17 @@
|
|||||||
import '../alarm/alarm.dart' show AlarmType;
|
import '../alarm/alarm.dart' show AlarmType;
|
||||||
|
import '../alarm/relative_time_alarm.dart';
|
||||||
import 'create_alarm_request.dart';
|
import 'create_alarm_request.dart';
|
||||||
|
|
||||||
class CreateRelativeTimeAlarmRequest extends CreateAlarmRequest {
|
class CreateRelativeTimeAlarmRequest extends CreateAlarmRequest {
|
||||||
final DateTime? triggerAt;
|
final DateTime? triggerAt;
|
||||||
|
|
||||||
CreateRelativeTimeAlarmRequest({this.triggerAt})
|
const CreateRelativeTimeAlarmRequest({this.triggerAt})
|
||||||
: super(alarmType: AlarmType.timeRelative);
|
: super(alarmType: AlarmType.timeRelative);
|
||||||
|
|
||||||
|
CreateRelativeTimeAlarmRequest.fromAlarm(RelativeTimeAlarm alarm)
|
||||||
|
: triggerAt = alarm.triggerAt,
|
||||||
|
super(alarmType: AlarmType.timeRelative);
|
||||||
|
|
||||||
|
RelativeTimeAlarm toRelativeTimeAlarm(String id) =>
|
||||||
|
RelativeTimeAlarm(id: id, triggerAt: triggerAt!);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import '../alarm/alarm.dart';
|
||||||
import '../task.dart';
|
import '../task.dart';
|
||||||
|
|
||||||
class CreateTaskRequest {
|
class CreateTaskRequest {
|
||||||
@@ -9,6 +10,7 @@ class CreateTaskRequest {
|
|||||||
final String category;
|
final String category;
|
||||||
final List<Task> subtasks;
|
final List<Task> subtasks;
|
||||||
final String url;
|
final String url;
|
||||||
|
final List<Alarm> alarms;
|
||||||
|
|
||||||
CreateTaskRequest({
|
CreateTaskRequest({
|
||||||
required this.title,
|
required this.title,
|
||||||
@@ -19,6 +21,7 @@ class CreateTaskRequest {
|
|||||||
required this.category,
|
required this.category,
|
||||||
required this.subtasks,
|
required this.subtasks,
|
||||||
required this.url,
|
required this.url,
|
||||||
|
required this.alarms,
|
||||||
});
|
});
|
||||||
|
|
||||||
CreateTaskRequest.fromTask(Task task)
|
CreateTaskRequest.fromTask(Task task)
|
||||||
@@ -29,7 +32,8 @@ class CreateTaskRequest {
|
|||||||
isCompleted = task.isCompleted,
|
isCompleted = task.isCompleted,
|
||||||
category = task.category,
|
category = task.category,
|
||||||
subtasks = task.subtasks,
|
subtasks = task.subtasks,
|
||||||
url = task.url;
|
url = task.url,
|
||||||
|
alarms = task.alarms;
|
||||||
|
|
||||||
Task toTask({required String id}) {
|
Task toTask({required String id}) {
|
||||||
return Task(
|
return Task(
|
||||||
@@ -42,6 +46,7 @@ class CreateTaskRequest {
|
|||||||
category: category,
|
category: category,
|
||||||
subtasks: subtasks,
|
subtasks: subtasks,
|
||||||
url: url,
|
url: url,
|
||||||
|
alarms: alarms,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-1
@@ -1,3 +1,4 @@
|
|||||||
|
import 'alarm/alarm.dart';
|
||||||
import 'location.dart';
|
import 'location.dart';
|
||||||
|
|
||||||
class Task {
|
class Task {
|
||||||
@@ -10,6 +11,7 @@ class Task {
|
|||||||
final String category;
|
final String category;
|
||||||
final List<Task> subtasks;
|
final List<Task> subtasks;
|
||||||
final String url;
|
final String url;
|
||||||
|
final List<Alarm> alarms;
|
||||||
|
|
||||||
Task({
|
Task({
|
||||||
required this.id,
|
required this.id,
|
||||||
@@ -21,6 +23,7 @@ class Task {
|
|||||||
this.category = '',
|
this.category = '',
|
||||||
this.subtasks = const [],
|
this.subtasks = const [],
|
||||||
this.url = '',
|
this.url = '',
|
||||||
|
required this.alarms,
|
||||||
});
|
});
|
||||||
|
|
||||||
Task copyWith({
|
Task copyWith({
|
||||||
@@ -32,7 +35,7 @@ class Task {
|
|||||||
bool? isCompleted,
|
bool? isCompleted,
|
||||||
String? category,
|
String? category,
|
||||||
List<Task>? subtasks,
|
List<Task>? subtasks,
|
||||||
List<DateTime>? alarms,
|
List<Alarm>? alarms,
|
||||||
Location? location,
|
Location? location,
|
||||||
String? url,
|
String? url,
|
||||||
}) {
|
}) {
|
||||||
@@ -46,6 +49,7 @@ class Task {
|
|||||||
category: category ?? this.category,
|
category: category ?? this.category,
|
||||||
subtasks: subtasks ?? this.subtasks,
|
subtasks: subtasks ?? this.subtasks,
|
||||||
url: url ?? this.url,
|
url: url ?? this.url,
|
||||||
|
alarms: alarms ?? this.alarms,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,6 +70,11 @@ class Task {
|
|||||||
.toList() ??
|
.toList() ??
|
||||||
[],
|
[],
|
||||||
url: json['url'] as String? ?? '',
|
url: json['url'] as String? ?? '',
|
||||||
|
alarms:
|
||||||
|
(json['alarms'] as List<dynamic>?)
|
||||||
|
?.map((e) => Alarm.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList() ??
|
||||||
|
[],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +89,7 @@ class Task {
|
|||||||
'category': category,
|
'category': category,
|
||||||
'subtasks': subtasks.map((e) => e.toJson()).toList(),
|
'subtasks': subtasks.map((e) => e.toJson()).toList(),
|
||||||
'url': url,
|
'url': url,
|
||||||
|
'alarms': alarms.map((e) => e.toJson()).toList(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ class _TaskEditPageState extends State<TaskEditPage> {
|
|||||||
category: categoryController.text,
|
category: categoryController.text,
|
||||||
subtasks: [],
|
subtasks: [],
|
||||||
url: urlController.text,
|
url: urlController.text,
|
||||||
|
alarms: [],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user