diff --git a/lib/components/task.dart b/lib/components/task.dart index 0312779..5b0ed05 100644 --- a/lib/components/task.dart +++ b/lib/components/task.dart @@ -5,8 +5,9 @@ import '../api/task.dart'; import '../globals.dart'; class TaskView extends StatefulWidget { - const TaskView(this.task, {super.key}); + const TaskView(this.task, this.index, {super.key}); final TaskDetail task; + final int index; @override State createState() => _TaskView(); @@ -82,20 +83,27 @@ class _TaskView extends State { Widget build(BuildContext context) { return Container( padding: const EdgeInsets.all(8.0), - child: Column(children: [ - _buildText(context), - LinearPercentIndicator( - animation: true, - animateFromLastPercent: true, - progressColor: Colors.green, - lineHeight: 20.0, - barRadius: const Radius.circular(10), - padding: EdgeInsets.zero, - center: - Text(percentText, style: const TextStyle(color: Colors.black)), - percent: percent, - ), - ]), + child: GestureDetector( + onTap: () {}, + child: Row(children: [ + Expanded( + child: Column(children: [ + _buildText(context), + LinearPercentIndicator( + animation: true, + animateFromLastPercent: true, + progressColor: Colors.green, + lineHeight: 20.0, + barRadius: const Radius.circular(10), + padding: EdgeInsets.zero, + center: Text(percentText, + style: const TextStyle(color: Colors.black)), + percent: percent, + ), + ])), + ReorderableDragStartListener( + index: widget.index, child: const Icon(Icons.reorder)), + ])), ); } } diff --git a/lib/task_manager.dart b/lib/task_manager.dart index 96a163f..2946886 100644 --- a/lib/task_manager.dart +++ b/lib/task_manager.dart @@ -99,7 +99,7 @@ class _TaskManagerPage extends State return Padding( padding: const EdgeInsets.all(8), key: ValueKey("task_${task.base.id}"), - child: TaskView(task)); + child: TaskView(task, index)); } Widget _proxyDecorator(Widget child, int index, Animation animation) { @@ -117,7 +117,15 @@ class _TaskManagerPage extends State ); } - void _onReorder(int oldIndex, int newIndex) {} + void _onReorder(int oldIndex, int newIndex) { + setState(() { + if (oldIndex < newIndex) { + newIndex -= 1; + } + final task = tasks.tasksList.removeAt(oldIndex); + tasks.tasksList.insert(newIndex, task); + }); + } Widget _buildList(BuildContext context) { return SliverReorderableList(