Compare commits
4 Commits
8be30974dd
...
cee5af0f84
| Author | SHA1 | Date | |
|---|---|---|---|
| cee5af0f84 | |||
| 999023e48a | |||
| 82a74a66b5 | |||
| e645081204 |
@@ -3,6 +3,7 @@ import 'time_alarm.dart';
|
|||||||
|
|
||||||
abstract class Alarm {
|
abstract class Alarm {
|
||||||
String get id;
|
String get id;
|
||||||
|
String get taskId;
|
||||||
Map<String, dynamic> toJson();
|
Map<String, dynamic> toJson();
|
||||||
|
|
||||||
factory Alarm.fromJson(Map<String, dynamic> json) {
|
factory Alarm.fromJson(Map<String, dynamic> json) {
|
||||||
@@ -25,5 +26,5 @@ abstract class Alarm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode => id.hashCode;
|
int get hashCode => taskId.hashCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ class CreateTaskRequest {
|
|||||||
final bool isCompleted;
|
final bool isCompleted;
|
||||||
final String category;
|
final String category;
|
||||||
final List<Task> subtasks;
|
final List<Task> subtasks;
|
||||||
final List<DateTime> alarms;
|
|
||||||
final Location? location;
|
|
||||||
final String url;
|
final String url;
|
||||||
|
|
||||||
CreateTaskRequest({
|
CreateTaskRequest({
|
||||||
@@ -21,8 +19,6 @@ class CreateTaskRequest {
|
|||||||
required this.isCompleted,
|
required this.isCompleted,
|
||||||
required this.category,
|
required this.category,
|
||||||
required this.subtasks,
|
required this.subtasks,
|
||||||
required this.alarms,
|
|
||||||
required this.location,
|
|
||||||
required this.url,
|
required this.url,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -34,8 +30,6 @@ class CreateTaskRequest {
|
|||||||
isCompleted = task.isCompleted,
|
isCompleted = task.isCompleted,
|
||||||
category = task.category,
|
category = task.category,
|
||||||
subtasks = task.subtasks,
|
subtasks = task.subtasks,
|
||||||
alarms = task.alarms,
|
|
||||||
location = task.location,
|
|
||||||
url = task.url;
|
url = task.url;
|
||||||
|
|
||||||
Task toTask({required String id}) {
|
Task toTask({required String id}) {
|
||||||
@@ -48,8 +42,6 @@ class CreateTaskRequest {
|
|||||||
isCompleted: isCompleted,
|
isCompleted: isCompleted,
|
||||||
category: category,
|
category: category,
|
||||||
subtasks: subtasks,
|
subtasks: subtasks,
|
||||||
alarms: alarms,
|
|
||||||
location: location,
|
|
||||||
url: url,
|
url: url,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,16 @@ 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;
|
||||||
|
|
||||||
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,
|
||||||
});
|
});
|
||||||
@@ -18,6 +22,7 @@ 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,
|
||||||
);
|
);
|
||||||
@@ -27,6 +32,7 @@ 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,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ class Task {
|
|||||||
final bool isCompleted;
|
final bool isCompleted;
|
||||||
final String category;
|
final String category;
|
||||||
final List<Task> subtasks;
|
final List<Task> subtasks;
|
||||||
final List<DateTime> alarms;
|
|
||||||
final Location? location;
|
|
||||||
final String url;
|
final String url;
|
||||||
|
|
||||||
Task({
|
Task({
|
||||||
@@ -22,8 +20,6 @@ class Task {
|
|||||||
this.isCompleted = false,
|
this.isCompleted = false,
|
||||||
this.category = '',
|
this.category = '',
|
||||||
this.subtasks = const [],
|
this.subtasks = const [],
|
||||||
this.alarms = const [],
|
|
||||||
this.location,
|
|
||||||
this.url = '',
|
this.url = '',
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -49,8 +45,6 @@ class Task {
|
|||||||
isCompleted: isCompleted ?? this.isCompleted,
|
isCompleted: isCompleted ?? this.isCompleted,
|
||||||
category: category ?? this.category,
|
category: category ?? this.category,
|
||||||
subtasks: subtasks ?? this.subtasks,
|
subtasks: subtasks ?? this.subtasks,
|
||||||
alarms: alarms ?? this.alarms,
|
|
||||||
location: location ?? this.location,
|
|
||||||
url: url ?? this.url,
|
url: url ?? this.url,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -71,14 +65,6 @@ class Task {
|
|||||||
?.map((e) => Task.fromJson(e as Map<String, dynamic>))
|
?.map((e) => Task.fromJson(e as Map<String, dynamic>))
|
||||||
.toList() ??
|
.toList() ??
|
||||||
[],
|
[],
|
||||||
alarms:
|
|
||||||
(json['alarms'] as List<dynamic>?)
|
|
||||||
?.map((e) => DateTime.parse(e as String))
|
|
||||||
.toList() ??
|
|
||||||
[],
|
|
||||||
location: json['location'] != null
|
|
||||||
? Location.fromJson(json['location'] as Map<String, dynamic>)
|
|
||||||
: null,
|
|
||||||
url: json['url'] as String? ?? '',
|
url: json['url'] as String? ?? '',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -93,8 +79,6 @@ class Task {
|
|||||||
'isCompleted': isCompleted,
|
'isCompleted': isCompleted,
|
||||||
'category': category,
|
'category': category,
|
||||||
'subtasks': subtasks.map((e) => e.toJson()).toList(),
|
'subtasks': subtasks.map((e) => e.toJson()).toList(),
|
||||||
'alarms': alarms.map((e) => e.toIso8601String()).toList(),
|
|
||||||
'location': location?.toJson(),
|
|
||||||
'url': url,
|
'url': url,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,19 +4,31 @@ class TimeAlarm implements Alarm {
|
|||||||
@override
|
@override
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
|
@override
|
||||||
|
final String taskId;
|
||||||
|
|
||||||
final DateTime triggerAt;
|
final DateTime triggerAt;
|
||||||
|
|
||||||
const TimeAlarm({required this.id, required this.triggerAt});
|
const TimeAlarm({
|
||||||
|
required this.id,
|
||||||
|
required this.taskId,
|
||||||
|
required this.triggerAt,
|
||||||
|
});
|
||||||
|
|
||||||
factory TimeAlarm.fromJson(Map<String, dynamic> json) {
|
factory TimeAlarm.fromJson(Map<String, dynamic> json) {
|
||||||
return TimeAlarm(
|
return TimeAlarm(
|
||||||
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),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
return {'id': id, 'triggerAt': triggerAt.toIso8601String()};
|
return {
|
||||||
|
'id': id,
|
||||||
|
'taskId': taskId,
|
||||||
|
'triggerAt': triggerAt.toIso8601String(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,8 +139,6 @@ class _TaskEditPageState extends State<TaskEditPage> {
|
|||||||
isCompleted: false,
|
isCompleted: false,
|
||||||
category: categoryController.text,
|
category: categoryController.text,
|
||||||
subtasks: [],
|
subtasks: [],
|
||||||
alarms: [],
|
|
||||||
location: null,
|
|
||||||
url: urlController.text,
|
url: urlController.text,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../model/alarm.dart';
|
||||||
|
import '../model/repositories/interfaces/alarm_repository.dart';
|
||||||
|
|
||||||
|
class AlarmController extends ChangeNotifier {
|
||||||
|
AlarmController(AlarmRepository repository) : _repository = repository {
|
||||||
|
_loadAlarms();
|
||||||
|
}
|
||||||
|
|
||||||
|
final AlarmRepository _repository;
|
||||||
|
|
||||||
|
final List<Alarm> _alarms = [];
|
||||||
|
|
||||||
|
Future<void> addAlarm(Alarm alarm) {
|
||||||
|
_alarms.add(alarm);
|
||||||
|
notifyListeners();
|
||||||
|
return _repository.createAlarm(alarm);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> deleteAlarm(Alarm alarm) {
|
||||||
|
_alarms.remove(alarm);
|
||||||
|
notifyListeners();
|
||||||
|
return _repository.deleteAlarm(alarm);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _loadAlarms() {
|
||||||
|
_alarms.clear();
|
||||||
|
return _repository.loadAlarms().then((value) => _alarms.addAll(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user