mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-06-17 08:24:45 +08:00
Add reorder button
This commit is contained in:
@@ -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<StatefulWidget> createState() => _TaskView();
|
||||
@@ -82,20 +83,27 @@ class _TaskView extends State<TaskView> {
|
||||
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)),
|
||||
])),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ class _TaskManagerPage extends State<TaskManagerPage>
|
||||
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<double> animation) {
|
||||
@@ -117,7 +117,15 @@ class _TaskManagerPage extends State<TaskManagerPage>
|
||||
);
|
||||
}
|
||||
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user