Compare commits
5 Commits
18ce2d9ccf
...
c5fafc2053
| Author | SHA1 | Date | |
|---|---|---|---|
| c5fafc2053 | |||
| a4e8dc0541 | |||
| 10ae8df737 | |||
| db8bc0b904 | |||
| 7b9188e2e8 |
@@ -0,0 +1,3 @@
|
|||||||
|
abstract class Alarm {
|
||||||
|
String get id;
|
||||||
|
}
|
||||||
+4
-10
@@ -1,16 +1,10 @@
|
|||||||
import 'latlng.dart';
|
import 'latlng.dart';
|
||||||
|
|
||||||
class Location {
|
class Location {
|
||||||
final String? _address;
|
final LatLng coordinates;
|
||||||
final LatLng? _coordinates;
|
final String address;
|
||||||
|
|
||||||
Location({this._address, this._coordinates});
|
Location({required this.coordinates, this.address = ''});
|
||||||
|
|
||||||
Location.fromAddress({required this._address}) : _coordinates = null;
|
|
||||||
Location.fromCoordinates({required this._coordinates}) : _address = null;
|
|
||||||
|
|
||||||
String get address => _address ?? '';
|
|
||||||
LatLng get coordinates => _coordinates ?? LatLng.empty();
|
|
||||||
|
|
||||||
factory Location.fromJson(Map<String, dynamic> json) {
|
factory Location.fromJson(Map<String, dynamic> json) {
|
||||||
return Location(
|
return Location(
|
||||||
@@ -20,6 +14,6 @@ class Location {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
return {'address': address, 'coordinates': coordinates};
|
return {'address': address, 'coordinates': coordinates.toJson()};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import 'alarm.dart';
|
||||||
|
import 'location.dart';
|
||||||
|
|
||||||
|
class LocationAlarm implements Alarm {
|
||||||
|
@override
|
||||||
|
final String id;
|
||||||
|
|
||||||
|
final Location location;
|
||||||
|
|
||||||
|
final int radiusMeters;
|
||||||
|
|
||||||
|
const LocationAlarm({
|
||||||
|
required this.id,
|
||||||
|
required this.location,
|
||||||
|
required this.radiusMeters,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory LocationAlarm.fromJson(Map<String, dynamic> json) {
|
||||||
|
return LocationAlarm(
|
||||||
|
id: json['id'] as String,
|
||||||
|
location: Location.fromJson(json['location'] as Map<String, dynamic>),
|
||||||
|
radiusMeters: json['radiusMeters'] as int,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
'id': id,
|
||||||
|
'location': location.toJson(),
|
||||||
|
'radiusMeters': radiusMeters,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import '../../alarm.dart';
|
||||||
|
|
||||||
|
abstract class AlarmRepository {
|
||||||
|
// Create
|
||||||
|
|
||||||
|
Future<void> createAlarm(Alarm alarm);
|
||||||
|
|
||||||
|
// Read
|
||||||
|
|
||||||
|
Future<List<Alarm>> loadAlarms();
|
||||||
|
|
||||||
|
// Update
|
||||||
|
|
||||||
|
Future<void> updateAlarm(Alarm alarm);
|
||||||
|
|
||||||
|
// Delete
|
||||||
|
|
||||||
|
Future<void> deleteAlarm(Alarm alarm);
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import 'alarm.dart';
|
||||||
|
|
||||||
|
class TimeAlarm implements Alarm {
|
||||||
|
@override
|
||||||
|
final String id;
|
||||||
|
|
||||||
|
final DateTime triggerAt;
|
||||||
|
|
||||||
|
const TimeAlarm({required this.id, required this.triggerAt});
|
||||||
|
|
||||||
|
factory TimeAlarm.fromJson(Map<String, dynamic> json) {
|
||||||
|
return TimeAlarm(
|
||||||
|
id: json['id'] as String,
|
||||||
|
triggerAt: DateTime.parse(json['triggerAt'] as String),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {'id': id, 'triggerAt': triggerAt.toIso8601String()};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import '../model/task.dart';
|
|||||||
import '../service/task_controller.dart';
|
import '../service/task_controller.dart';
|
||||||
import '../service/tools.dart';
|
import '../service/tools.dart';
|
||||||
import '../service/validators.dart';
|
import '../service/validators.dart';
|
||||||
|
import '../widgets/time_selector.dart';
|
||||||
|
|
||||||
class TaskEditPage extends StatefulWidget {
|
class TaskEditPage extends StatefulWidget {
|
||||||
static const routeName = '/edit';
|
static const routeName = '/edit';
|
||||||
@@ -96,69 +97,12 @@ class _TaskEditPageState extends State<TaskEditPage> {
|
|||||||
minLines: 3,
|
minLines: 3,
|
||||||
maxLines: 10,
|
maxLines: 10,
|
||||||
),
|
),
|
||||||
Flex(
|
TimeSelector(
|
||||||
direction: Axis.horizontal,
|
initialDueDateTime: task?.due,
|
||||||
|
nextFocusNode: categoryFocusNode,
|
||||||
children: [
|
dueDateController: dueDateController,
|
||||||
Flexible(
|
dueTimeController: dueTimeController,
|
||||||
flex: 3,
|
formKey: formKey,
|
||||||
child: TextFormField(
|
|
||||||
focusNode: dueDateFocusNode,
|
|
||||||
controller: dueDateController,
|
|
||||||
onChanged: maybeEnableDueTime,
|
|
||||||
onFieldSubmitted: (_) {
|
|
||||||
isDueTimeEnabled
|
|
||||||
? dueDateFocusNode.nextFocus()
|
|
||||||
: categoryFocusNode.requestFocus();
|
|
||||||
},
|
|
||||||
decoration: InputDecoration(
|
|
||||||
label: Text('Due Date'),
|
|
||||||
suffixIcon: IconButton(
|
|
||||||
onPressed: () async {
|
|
||||||
final result = await onOpenCalendarPickerPressed();
|
|
||||||
if (result != null) {
|
|
||||||
final dateString = getIsoDateString(result);
|
|
||||||
dueDateController.text = dateString;
|
|
||||||
maybeEnableDueTime(dateString);
|
|
||||||
formKey.currentState?.validate();
|
|
||||||
dueTimeFocusNode.requestFocus();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
icon: Icon(Icons.calendar_month),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
validator: dateTimeValidator,
|
|
||||||
keyboardType: TextInputType.datetime,
|
|
||||||
textInputAction: TextInputAction.next,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(padding: EdgeInsetsGeometry.only(left: 10)),
|
|
||||||
Flexible(
|
|
||||||
flex: 2,
|
|
||||||
child: TextFormField(
|
|
||||||
focusNode: dueTimeFocusNode,
|
|
||||||
onFieldSubmitted: (_) => dueTimeFocusNode.nextFocus(),
|
|
||||||
controller: dueTimeController,
|
|
||||||
enabled: isDueTimeEnabled,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
label: Text('Due Time'),
|
|
||||||
suffixIcon: IconButton(
|
|
||||||
onPressed: () async {
|
|
||||||
final result = await onOpenTimePickerPressed();
|
|
||||||
if (result != null && context.mounted) {
|
|
||||||
dueTimeController.text = result.format(context);
|
|
||||||
categoryFocusNode.requestFocus();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
icon: Icon(Icons.schedule),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
validator: timeValidator,
|
|
||||||
keyboardType: TextInputType.text,
|
|
||||||
textInputAction: TextInputAction.next,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
focusNode: categoryFocusNode,
|
focusNode: categoryFocusNode,
|
||||||
@@ -184,27 +128,6 @@ class _TaskEditPageState extends State<TaskEditPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<DateTime?> onOpenCalendarPickerPressed() {
|
|
||||||
return showDialog<DateTime?>(
|
|
||||||
context: context,
|
|
||||||
builder: (context) => DatePickerDialog(
|
|
||||||
firstDate: DateTime(DateTime.now().year - 100),
|
|
||||||
lastDate: DateTime(DateTime.now().year + 100),
|
|
||||||
initialDate:
|
|
||||||
DateTime.tryParse(dueDateController.text) ?? DateTime.now(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<TimeOfDay?> onOpenTimePickerPressed() {
|
|
||||||
return showDialog<TimeOfDay?>(
|
|
||||||
context: context,
|
|
||||||
builder: (context) => TimePickerDialog(
|
|
||||||
initialTime: TimeOfDay.fromDateTime(task?.due ?? DateTime.now()),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onSavePressed() {
|
void onSavePressed() {
|
||||||
Navigator.of(context).pop(
|
Navigator.of(context).pop(
|
||||||
CreateTaskRequest(
|
CreateTaskRequest(
|
||||||
@@ -251,18 +174,4 @@ class _TaskEditPageState extends State<TaskEditPage> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void maybeEnableDueTime(String value) {
|
|
||||||
if (value.isNotEmpty &&
|
|
||||||
dateTimeValidator(value) == null &&
|
|
||||||
!isDueTimeEnabled) {
|
|
||||||
setState(() {
|
|
||||||
isDueTimeEnabled = true;
|
|
||||||
});
|
|
||||||
} else if (isDueTimeEnabled) {
|
|
||||||
setState(() {
|
|
||||||
isDueTimeEnabled = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../service/tools.dart' show getIsoDateString;
|
||||||
|
import '../service/validators.dart';
|
||||||
|
|
||||||
|
class TimeSelector extends StatefulWidget {
|
||||||
|
const TimeSelector({
|
||||||
|
super.key,
|
||||||
|
this.initialDueDateTime,
|
||||||
|
this.nextFocusNode,
|
||||||
|
required this.dueDateController,
|
||||||
|
required this.dueTimeController,
|
||||||
|
this.formKey,
|
||||||
|
});
|
||||||
|
|
||||||
|
final DateTime? initialDueDateTime;
|
||||||
|
final GlobalKey<FormState>? formKey;
|
||||||
|
final FocusNode? nextFocusNode;
|
||||||
|
final TextEditingController dueDateController;
|
||||||
|
final TextEditingController dueTimeController;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<TimeSelector> createState() => _TimeSelectorState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TimeSelectorState extends State<TimeSelector> {
|
||||||
|
final dueDateFocusNode = FocusNode();
|
||||||
|
|
||||||
|
final dueTimeFocusNode = FocusNode();
|
||||||
|
|
||||||
|
bool isDueTimeEnabled = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
isDueTimeEnabled = widget.initialDueDateTime != null;
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Flex(
|
||||||
|
direction: Axis.horizontal,
|
||||||
|
|
||||||
|
children: [
|
||||||
|
Flexible(
|
||||||
|
flex: 3,
|
||||||
|
child: TextFormField(
|
||||||
|
focusNode: dueDateFocusNode,
|
||||||
|
controller: widget.dueDateController,
|
||||||
|
onChanged: maybeEnableDueTime,
|
||||||
|
onFieldSubmitted: (_) {
|
||||||
|
isDueTimeEnabled
|
||||||
|
? dueDateFocusNode.nextFocus()
|
||||||
|
: widget.nextFocusNode?.requestFocus();
|
||||||
|
},
|
||||||
|
decoration: InputDecoration(
|
||||||
|
label: Text('Due Date'),
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
onPressed: () async {
|
||||||
|
final result = await onOpenCalendarPickerPressed();
|
||||||
|
if (result != null) {
|
||||||
|
final dateString = getIsoDateString(result);
|
||||||
|
widget.dueDateController.text = dateString;
|
||||||
|
maybeEnableDueTime(dateString);
|
||||||
|
widget.formKey?.currentState?.validate();
|
||||||
|
dueTimeFocusNode.requestFocus();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
icon: Icon(Icons.calendar_month),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
validator: dateTimeValidator,
|
||||||
|
keyboardType: TextInputType.datetime,
|
||||||
|
textInputAction: TextInputAction.next,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(padding: EdgeInsetsGeometry.only(left: 10)),
|
||||||
|
Flexible(
|
||||||
|
flex: 2,
|
||||||
|
child: TextFormField(
|
||||||
|
focusNode: dueTimeFocusNode,
|
||||||
|
onFieldSubmitted: (_) => dueTimeFocusNode.nextFocus(),
|
||||||
|
controller: widget.dueTimeController,
|
||||||
|
enabled: isDueTimeEnabled,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
label: Text('Due Time'),
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
onPressed: () async {
|
||||||
|
final result = await onOpenTimePickerPressed();
|
||||||
|
if (result != null && context.mounted) {
|
||||||
|
widget.dueTimeController.text = result.format(context);
|
||||||
|
widget.nextFocusNode?.requestFocus();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
icon: Icon(Icons.schedule),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
validator: timeValidator,
|
||||||
|
keyboardType: TextInputType.text,
|
||||||
|
textInputAction: TextInputAction.next,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<DateTime?> onOpenCalendarPickerPressed() {
|
||||||
|
return showDialog<DateTime?>(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => DatePickerDialog(
|
||||||
|
firstDate: DateTime(DateTime.now().year - 100),
|
||||||
|
lastDate: DateTime(DateTime.now().year + 100),
|
||||||
|
initialDate:
|
||||||
|
DateTime.tryParse(widget.dueDateController.text) ?? DateTime.now(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<TimeOfDay?> onOpenTimePickerPressed() {
|
||||||
|
return showDialog<TimeOfDay?>(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => TimePickerDialog(
|
||||||
|
initialTime: TimeOfDay.fromDateTime(
|
||||||
|
widget.initialDueDateTime ?? DateTime.now(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void maybeEnableDueTime(String value) {
|
||||||
|
if (value.isNotEmpty && dateTimeValidator(value) == null) {
|
||||||
|
setState(() {
|
||||||
|
isDueTimeEnabled = true;
|
||||||
|
});
|
||||||
|
} else if (isDueTimeEnabled) {
|
||||||
|
setState(() {
|
||||||
|
isDueTimeEnabled = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user