mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-08 17:40:28 +00:00
fix: task view ui
This commit is contained in:
1 parent
4128e718e9
commit
5558cac263
16 files changed
+149
-144
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../controllers/task_controller.dart';
|
||||
import '../controllers/task_downloaded_controller.dart';
|
||||
import '../controllers/task_downloading_controller.dart';
|
||||
|
||||
class TaskBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut<TaskController>(
|
||||
() => TaskController(),
|
||||
);
|
||||
Get.lazyPut<TaskDownloadingController>(
|
||||
() => TaskDownloadingController(),
|
||||
);
|
||||
Get.lazyPut<TaskDownloadedController>(
|
||||
() => TaskDownloadedController(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class TaskController extends GetxController {
|
||||
final tabIndex = 0.obs;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:gopeed/app/modules/task/controllers/task_list_controller.dart';
|
||||
|
||||
import '../../../../api/model/task.dart';
|
||||
|
||||
class TaskDownloadedController extends TaskListController {
|
||||
TaskDownloadedController() : super([Status.done]);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import '../../../../api/model/task.dart';
|
||||
import 'task_list_controller.dart';
|
||||
|
||||
class TaskDownloadingController extends TaskListController {
|
||||
TaskDownloadingController()
|
||||
: super([Status.ready, Status.running, Status.pause, Status.error]);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../../../api/api.dart';
|
||||
import '../../../../api/model/task.dart';
|
||||
|
||||
abstract class TaskListController extends GetxController {
|
||||
List<Status> statuses;
|
||||
|
||||
TaskListController(this.statuses);
|
||||
|
||||
final tasks = <Task>[].obs;
|
||||
final isRunning = false.obs;
|
||||
|
||||
late final Timer _timer;
|
||||
|
||||
@override
|
||||
void onInit() async {
|
||||
super.onInit();
|
||||
|
||||
start();
|
||||
_timer = Timer.periodic(const Duration(milliseconds: 1000), (timer) async {
|
||||
if (isRunning.value) {
|
||||
await getTasksState();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
super.onClose();
|
||||
_timer.cancel();
|
||||
}
|
||||
|
||||
void start() async {
|
||||
await getTasksState();
|
||||
isRunning.value = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
isRunning.value = false;
|
||||
}
|
||||
|
||||
getTasksState() async {
|
||||
tasks.value = await getTasks(statuses);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../../views/views/buid_task_list_view.dart';
|
||||
import '../controllers/task_downloaded_controller.dart';
|
||||
|
||||
class TaskDownloadedView extends GetView<TaskDownloadedController> {
|
||||
const TaskDownloadedView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BuildTaskListView(tasks: controller.tasks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../../views/views/buid_task_list_view.dart';
|
||||
import '../controllers/task_downloading_controller.dart';
|
||||
|
||||
class TaskDownloadingView extends GetView<TaskDownloadingController> {
|
||||
const TaskDownloadingView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BuildTaskListView(tasks: controller.tasks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:gopeed/app/modules/task/controllers/task_downloading_controller.dart';
|
||||
import '../controllers/task_downloaded_controller.dart';
|
||||
import 'task_downloading_view.dart';
|
||||
|
||||
import 'task_downloaded_view.dart';
|
||||
import '../controllers/task_controller.dart';
|
||||
|
||||
class TaskView extends GetView<TaskController> {
|
||||
const TaskView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DefaultTabController(
|
||||
length: 2,
|
||||
child: Scaffold(
|
||||
appBar: PreferredSize(
|
||||
preferredSize: const Size.fromHeight(56),
|
||||
child: AppBar(
|
||||
bottom: TabBar(
|
||||
tabs: const [
|
||||
Tab(
|
||||
icon: Icon(Icons.file_download),
|
||||
),
|
||||
Tab(
|
||||
icon: Icon(Icons.done),
|
||||
),
|
||||
],
|
||||
onTap: (index) {
|
||||
if (controller.tabIndex.value != index) {
|
||||
controller.tabIndex.value = index;
|
||||
final downloadingController =
|
||||
Get.find<TaskDownloadingController>();
|
||||
final downloadedController =
|
||||
Get.find<TaskDownloadedController>();
|
||||
switch (index) {
|
||||
case 0:
|
||||
downloadingController.start();
|
||||
downloadedController.stop();
|
||||
break;
|
||||
case 1:
|
||||
downloadingController.stop();
|
||||
downloadedController.start();
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
)),
|
||||
body: const TabBarView(
|
||||
children: [
|
||||
TaskDownloadingView(),
|
||||
TaskDownloadedView(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user