From c3a7962679e6ba71924ee8c12cd1a445f3ab186f Mon Sep 17 00:00:00 2001 From: Paul Nettleton Date: Wed, 27 Jul 2022 13:10:01 -0500 Subject: [PATCH] edit task color, update edited task, some cleanup --- lib/components/BucketTaskCard.dart | 6 +- lib/components/TaskTile.dart | 30 +- lib/models/task.dart | 38 ++ lib/pages/list/list.dart | 12 +- lib/pages/list/task_edit.dart | 567 +++++++++++++++++------------ pubspec.lock | 7 + pubspec.yaml | 1 + 7 files changed, 403 insertions(+), 258 deletions(-) diff --git a/lib/components/BucketTaskCard.dart b/lib/components/BucketTaskCard.dart index 690acb9..0ae183a 100644 --- a/lib/components/BucketTaskCard.dart +++ b/lib/components/BucketTaskCard.dart @@ -174,12 +174,14 @@ class _BucketTaskCardState extends State { ), ), ), - onTap: () => Navigator.push( + onTap: () => Navigator.push( context, MaterialPageRoute(builder: (context) => TaskEditPage( task: _currentTask, )), - ), + ).then((task) => setState(() { + if (task != null) _currentTask = task; + })), ), ); } diff --git a/lib/components/TaskTile.dart b/lib/components/TaskTile.dart index 633e4cf..caf77da 100644 --- a/lib/components/TaskTile.dart +++ b/lib/components/TaskTile.dart @@ -81,14 +81,16 @@ class TaskTileState extends State { : Text(_currentTask.description), secondary: IconButton(icon: Icon(Icons.settings), onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => TaskEditPage( - task: _currentTask, - ))).whenComplete(() { - widget.onEdit(); - }); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => TaskEditPage( + task: _currentTask, + ), + ), + ).then((task) => setState(() { + if (task != null) _currentTask = task; + })).whenComplete(() => widget.onEdit()); }), onChanged: _change, ); @@ -107,15 +109,9 @@ class TaskTileState extends State { } Future _updateTask(Task task, bool checked) { - // TODO use copyFrom - return VikunjaGlobal.of(context).taskService.update(Task( - id: task.id, - done: checked, - title: task.title, - description: task.description, - createdBy: task.createdBy, - dueDate: task.dueDate - )); + return VikunjaGlobal.of(context).taskService.update(task.copyWith( + done: checked, + )); } } diff --git a/lib/models/task.dart b/lib/models/task.dart index bd42e38..63fa76e 100644 --- a/lib/models/task.dart +++ b/lib/models/task.dart @@ -107,4 +107,42 @@ class Task { Color get textColor => color != null ? color.computeLuminance() > 0.5 ? Colors.black : Colors.white : null; + + Task copyWith({ + int id, int parentTaskId, int priority, int listId, int bucketId, + DateTime created, DateTime updated, DateTime dueDate, DateTime startDate, DateTime endDate, + List reminderDates, + String title, String description, + bool done, + Color color, + bool resetColor, + User createdBy, + Duration repeatAfter, + List subtasks, + List