mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-06 00:25:43 +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
@@ -31,7 +31,7 @@ class CreateView extends GetView<CreateController> {
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: () => Get.rootDelegate.offNamed(Routes.DOWNLOADING)),
|
||||
onPressed: () => Get.rootDelegate.offNamed(Routes.TASK)),
|
||||
// actions: [],
|
||||
title: Text('create'.tr),
|
||||
),
|
||||
@@ -188,7 +188,7 @@ class CreateView extends GetView<CreateController> {
|
||||
selectFiles: controller.selectedIndexes
|
||||
.cast<int>())));
|
||||
Get.back();
|
||||
Get.rootDelegate.offNamed(Routes.DOWNLOADING);
|
||||
Get.rootDelegate.offNamed(Routes.TASK);
|
||||
}
|
||||
} catch (e) {
|
||||
showErrorMessage(e);
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../controllers/downloaded_controller.dart';
|
||||
|
||||
class DownloadedBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut<DownloadedController>(
|
||||
() => DownloadedController(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../../../api/api.dart';
|
||||
import '../../../../api/model/task.dart';
|
||||
|
||||
class DownloadedController extends GetxController {
|
||||
final tasks = <Task>[].obs;
|
||||
late final Timer _timer;
|
||||
|
||||
@override
|
||||
void onInit() async {
|
||||
super.onInit();
|
||||
await getTasksState();
|
||||
_timer = Timer.periodic(const Duration(milliseconds: 1000), (timer) async {
|
||||
// debugPrint('timer${DateTime.now()}');
|
||||
await getTasksState();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
super.onClose();
|
||||
_timer.cancel();
|
||||
}
|
||||
|
||||
getTasksState() async {
|
||||
tasks.value = await getTasks([Status.done]);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../controllers/downloading_controller.dart';
|
||||
|
||||
class DownloadingBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut<DownloadingController>(
|
||||
() => DownloadingController(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ class HomeView extends GetView<HomeController> {
|
||||
Widget build(BuildContext context) {
|
||||
return GetRouterOutlet.builder(builder: (context, delegate, currentRoute) {
|
||||
return Scaffold(
|
||||
extendBody: true,
|
||||
// extendBody: true,
|
||||
body: Row(
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -26,29 +26,20 @@ class HomeView extends GetView<HomeController> {
|
||||
onDestinationSelected: (int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
delegate.toNamed(Routes.DOWNLOADING);
|
||||
controller.currentIndex.value = 0;
|
||||
delegate.toNamed(Routes.TASK);
|
||||
break;
|
||||
case 1:
|
||||
delegate.toNamed(Routes.DOWNLOADED);
|
||||
controller.currentIndex.value = 1;
|
||||
break;
|
||||
case 2:
|
||||
delegate.toNamed(Routes.SETTING);
|
||||
controller.currentIndex.value = 2;
|
||||
break;
|
||||
}
|
||||
},
|
||||
destinations: [
|
||||
NavigationRailDestination(
|
||||
icon: const Icon(Icons.file_download),
|
||||
selectedIcon: const Icon(Icons.file_download),
|
||||
label: Text('downloading'.tr),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: const Icon(Icons.done),
|
||||
selectedIcon: const Icon(Icons.done),
|
||||
label: Text('downloaded'.tr),
|
||||
label: Text('task'.tr),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: const Icon(Icons.settings),
|
||||
@@ -63,7 +54,7 @@ class HomeView extends GetView<HomeController> {
|
||||
: const SizedBox.shrink(),
|
||||
Expanded(
|
||||
child: GetRouterOutlet(
|
||||
initialRoute: Routes.DOWNLOADING,
|
||||
initialRoute: Routes.TASK,
|
||||
// anchorRoute: '/',
|
||||
// filterPages: (afterAnchor) {
|
||||
// logger.w(afterAnchor);
|
||||
@@ -75,13 +66,9 @@ class HomeView extends GetView<HomeController> {
|
||||
bottomNavigationBar: ResponsiveBuilder.isNarrow(context)
|
||||
? BottomNavigationBar(
|
||||
items: <BottomNavigationBarItem>[
|
||||
BottomNavigationBarItem(
|
||||
icon: const Icon(Icons.file_download),
|
||||
label: 'downloading'.tr,
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: const Icon(Icons.done),
|
||||
label: 'downloaded'.tr,
|
||||
label: 'task'.tr,
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: const Icon(Icons.settings),
|
||||
@@ -93,16 +80,12 @@ class HomeView extends GetView<HomeController> {
|
||||
onTap: (index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
delegate.toNamed(Routes.DOWNLOADING);
|
||||
controller.currentIndex.value = 0;
|
||||
delegate.toNamed(Routes.TASK);
|
||||
break;
|
||||
case 1:
|
||||
delegate.toNamed(Routes.DOWNLOADED);
|
||||
controller.currentIndex.value = 1;
|
||||
break;
|
||||
case 2:
|
||||
delegate.toNamed(Routes.SETTING);
|
||||
controller.currentIndex.value = 2;
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
+21
-6
@@ -5,18 +5,25 @@ import 'package:get/get.dart';
|
||||
import '../../../../api/api.dart';
|
||||
import '../../../../api/model/task.dart';
|
||||
|
||||
class DownloadingController extends GetxController {
|
||||
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();
|
||||
await getTasksState();
|
||||
|
||||
start();
|
||||
_timer = Timer.periodic(const Duration(milliseconds: 1000), (timer) async {
|
||||
// debugPrint('timer${DateTime.now()}');
|
||||
await getTasksState();
|
||||
if (isRunning.value) {
|
||||
await getTasksState();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -26,8 +33,16 @@ class DownloadingController extends GetxController {
|
||||
_timer.cancel();
|
||||
}
|
||||
|
||||
void start() async {
|
||||
await getTasksState();
|
||||
isRunning.value = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
isRunning.value = false;
|
||||
}
|
||||
|
||||
getTasksState() async {
|
||||
tasks.value = await getTasks(
|
||||
[Status.ready, Status.running, Status.pause, Status.error]);
|
||||
tasks.value = await getTasks(statuses);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -2,10 +2,10 @@ import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../../views/views/buid_task_list_view.dart';
|
||||
import '../controllers/downloading_controller.dart';
|
||||
import '../controllers/task_downloaded_controller.dart';
|
||||
|
||||
class DownloadingView extends GetView<DownloadingController> {
|
||||
const DownloadingView({Key? key}) : super(key: key);
|
||||
class TaskDownloadedView extends GetView<TaskDownloadedController> {
|
||||
const TaskDownloadedView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
+3
-3
@@ -2,10 +2,10 @@ import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../../views/views/buid_task_list_view.dart';
|
||||
import '../controllers/downloaded_controller.dart';
|
||||
import '../controllers/task_downloading_controller.dart';
|
||||
|
||||
class DownloadedView extends GetView<DownloadedController> {
|
||||
const DownloadedView({Key? key}) : super(key: key);
|
||||
class TaskDownloadingView extends GetView<TaskDownloadingController> {
|
||||
const TaskDownloadingView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -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(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,21 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:gopeed/app/modules/task/views/task_view.dart';
|
||||
|
||||
import '../modules/create/bindings/create_binding.dart';
|
||||
import '../modules/create/views/create_view.dart';
|
||||
import '../modules/downloaded/bindings/downloaded_binding.dart';
|
||||
import '../modules/downloaded/views/downloaded_view.dart';
|
||||
import '../modules/downloading/bindings/downloading_binding.dart';
|
||||
import '../modules/downloading/views/downloading_view.dart';
|
||||
import '../modules/home/bindings/home_binding.dart';
|
||||
import '../modules/home/views/home_view.dart';
|
||||
import '../modules/root/bindings/root_binding.dart';
|
||||
import '../modules/root/views/root_view.dart';
|
||||
import '../modules/setting/bindings/setting_binding.dart';
|
||||
import '../modules/setting/views/setting_view.dart';
|
||||
import '../modules/task/bindings/task_binding.dart';
|
||||
|
||||
part 'app_routes.dart';
|
||||
|
||||
class AppPages {
|
||||
AppPages._();
|
||||
|
||||
static const INITIAL = Routes.ROOT;
|
||||
|
||||
static final routes = [
|
||||
GetPage(
|
||||
name: _Paths.ROOT,
|
||||
@@ -38,21 +34,14 @@ class AppPages {
|
||||
binding: HomeBinding(),
|
||||
children: [
|
||||
GetPage(
|
||||
name: _Paths.DOWNLOADED,
|
||||
transition: Transition.noTransition,
|
||||
page: () => const DownloadedView(),
|
||||
binding: DownloadedBinding(),
|
||||
),
|
||||
GetPage(
|
||||
name: _Paths.DOWNLOADING,
|
||||
transition: Transition.noTransition,
|
||||
page: () => const DownloadingView(),
|
||||
binding: DownloadingBinding(),
|
||||
),
|
||||
name: _Paths.TASK,
|
||||
page: () => const TaskView(),
|
||||
transition: Transition.noTransition,
|
||||
binding: TaskBinding()),
|
||||
GetPage(
|
||||
name: _Paths.SETTING,
|
||||
transition: Transition.noTransition,
|
||||
page: () => const SettingView(),
|
||||
transition: Transition.noTransition,
|
||||
binding: SettingBinding(),
|
||||
),
|
||||
]),
|
||||
|
||||
@@ -3,20 +3,18 @@ part of 'app_pages.dart';
|
||||
|
||||
abstract class Routes {
|
||||
Routes._();
|
||||
static const DOWNLOADED = _Paths.HOME + _Paths.DOWNLOADED;
|
||||
static const DOWNLOADING = _Paths.HOME + _Paths.DOWNLOADING;
|
||||
static const CREATE = _Paths.CREATE;
|
||||
static const ROOT = _Paths.ROOT;
|
||||
static const SETTING = _Paths.HOME + _Paths.SETTING;
|
||||
static const HOME = _Paths.HOME;
|
||||
static const CREATE = _Paths.CREATE;
|
||||
static const TASK = _Paths.HOME + _Paths.TASK;
|
||||
static const SETTING = _Paths.HOME + _Paths.SETTING;
|
||||
}
|
||||
|
||||
abstract class _Paths {
|
||||
_Paths._();
|
||||
static const DOWNLOADED = '/downloaded';
|
||||
static const DOWNLOADING = '/downloading';
|
||||
static const CREATE = '/create';
|
||||
static const ROOT = '/';
|
||||
static const SETTING = '/setting';
|
||||
static const HOME = '/home';
|
||||
static const CREATE = '/create';
|
||||
static const TASK = '/task';
|
||||
static const SETTING = '/setting';
|
||||
}
|
||||
@@ -23,32 +23,6 @@ class BuildTaskListView extends GetView {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
// actions: <Widget>[
|
||||
// // IconButton(
|
||||
// // icon: const Icon(Icons.add),
|
||||
// // tooltip: 'create'.tr,
|
||||
// // onPressed: () {
|
||||
// // Get.rootDelegate.toNamed(Routes.CREATE);
|
||||
// // },
|
||||
// // ),
|
||||
// //TODO appBar toggleALl/start selected/delete selected/
|
||||
// // IconButton(
|
||||
// // icon: const Icon(Icons.pause),
|
||||
// // tooltip: 'title'.tr,
|
||||
// // onPressed: () {
|
||||
// // // pause all
|
||||
// // },
|
||||
// // ),
|
||||
// // IconButton(
|
||||
// // icon: const Icon(Icons.delete),
|
||||
// // tooltip: 'title'.tr,
|
||||
// // onPressed: () {
|
||||
// // // delete all
|
||||
// // },
|
||||
// // )
|
||||
// ],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
Get.rootDelegate.toNamed(Routes.CREATE);
|
||||
|
||||
Reference in new issue
Block a user