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