Compare commits
4 Commits
v0.1.1
...
cee5af0f84
| Author | SHA1 | Date | |
|---|---|---|---|
| cee5af0f84 | |||
| 999023e48a | |||
| 82a74a66b5 | |||
| e645081204 |
@@ -3,6 +3,7 @@ import 'time_alarm.dart';
|
||||
|
||||
abstract class Alarm {
|
||||
String get id;
|
||||
String get taskId;
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
factory Alarm.fromJson(Map<String, dynamic> json) {
|
||||
@@ -25,5 +26,5 @@ abstract class Alarm {
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => id.hashCode;
|
||||
int get hashCode => taskId.hashCode;
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ class CreateTaskRequest {
|
||||
final bool isCompleted;
|
||||
final String category;
|
||||
final List<Task> subtasks;
|
||||
final List<DateTime> alarms;
|
||||
final Location? location;
|
||||
final String url;
|
||||
|
||||
CreateTaskRequest({
|
||||
@@ -21,8 +19,6 @@ class CreateTaskRequest {
|
||||
required this.isCompleted,
|
||||
required this.category,
|
||||
required this.subtasks,
|
||||
required this.alarms,
|
||||
required this.location,
|
||||
required this.url,
|
||||
});
|
||||
|
||||
@@ -34,8 +30,6 @@ class CreateTaskRequest {
|
||||
isCompleted = task.isCompleted,
|
||||
category = task.category,
|
||||
subtasks = task.subtasks,
|
||||
alarms = task.alarms,
|
||||
location = task.location,
|
||||
url = task.url;
|
||||
|
||||
Task toTask({required String id}) {
|
||||
@@ -48,8 +42,6 @@ class CreateTaskRequest {
|
||||
isCompleted: isCompleted,
|
||||
category: category,
|
||||
subtasks: subtasks,
|
||||
alarms: alarms,
|
||||
location: location,
|
||||
url: url,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,12 +5,16 @@ class LocationAlarm implements Alarm {
|
||||
@override
|
||||
final String id;
|
||||
|
||||
@override
|
||||
final String taskId;
|
||||
|
||||
final Location location;
|
||||
|
||||
final int radiusMeters;
|
||||
|
||||
const LocationAlarm({
|
||||
required this.id,
|
||||
required this.taskId,
|
||||
required this.location,
|
||||
required this.radiusMeters,
|
||||
});
|
||||
@@ -18,6 +22,7 @@ class LocationAlarm implements Alarm {
|
||||
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,
|
||||
);
|
||||
@@ -27,6 +32,7 @@ class LocationAlarm implements Alarm {
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'taskId': taskId,
|
||||
'location': location.toJson(),
|
||||
'radiusMeters': radiusMeters,
|
||||
};
|
||||
|
||||
@@ -9,8 +9,6 @@ class Task {
|
||||
final bool isCompleted;
|
||||
final String category;
|
||||
final List<Task> subtasks;
|
||||
final List<DateTime> alarms;
|
||||
final Location? location;
|
||||
final String url;
|
||||
|
||||
Task({
|
||||
@@ -22,8 +20,6 @@ class Task {
|
||||
this.isCompleted = false,
|
||||
this.category = '',
|
||||
this.subtasks = const [],
|
||||
this.alarms = const [],
|
||||
this.location,
|
||||
this.url = '',
|
||||
});
|
||||
|
||||
@@ -49,8 +45,6 @@ class Task {
|
||||
isCompleted: isCompleted ?? this.isCompleted,
|
||||
category: category ?? this.category,
|
||||
subtasks: subtasks ?? this.subtasks,
|
||||
alarms: alarms ?? this.alarms,
|
||||
location: location ?? this.location,
|
||||
url: url ?? this.url,
|
||||
);
|
||||
}
|
||||
@@ -71,14 +65,6 @@ class Task {
|
||||
?.map((e) => Task.fromJson(e as Map<String, dynamic>))
|
||||
.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? ?? '',
|
||||
);
|
||||
}
|
||||
@@ -93,8 +79,6 @@ class Task {
|
||||
'isCompleted': isCompleted,
|
||||
'category': category,
|
||||
'subtasks': subtasks.map((e) => e.toJson()).toList(),
|
||||
'alarms': alarms.map((e) => e.toIso8601String()).toList(),
|
||||
'location': location?.toJson(),
|
||||
'url': url,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,19 +4,31 @@ class TimeAlarm implements Alarm {
|
||||
@override
|
||||
final String id;
|
||||
|
||||
@override
|
||||
final String taskId;
|
||||
|
||||
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) {
|
||||
return TimeAlarm(
|
||||
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, 'triggerAt': triggerAt.toIso8601String()};
|
||||
return {
|
||||
'id': id,
|
||||
'taskId': taskId,
|
||||
'triggerAt': triggerAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,8 +139,6 @@ class _TaskEditPageState extends State<TaskEditPage> {
|
||||
isCompleted: false,
|
||||
category: categoryController.text,
|
||||
subtasks: [],
|
||||
alarms: [],
|
||||
location: null,
|
||||
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