From 63535919352d8318be939fe193148099ecf24ab3 Mon Sep 17 00:00:00 2001 From: xkeyC <3334969096@qq.com> Date: Sat, 9 Mar 2024 20:22:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:riverpod=20=E8=BF=81=E7=A7=BB=20Index=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/app.dart | 14 ++- lib/main.dart | 1 - lib/ui/index_ui.dart | 137 ++++++++++++++++++++++++++++ lib/ui/settings/upgrade_dialog.dart | 5 +- lib/ui/splash_ui.dart | 10 +- lib/widgets/widgets.dart | 21 +++++ 6 files changed, 174 insertions(+), 14 deletions(-) create mode 100644 lib/ui/index_ui.dart diff --git a/lib/app.dart b/lib/app.dart index 648b798..727b403 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -13,6 +13,7 @@ import 'package:starcitizen_doctor/common/conf/const_conf.dart'; import 'package:starcitizen_doctor/common/utils/log.dart'; import 'package:starcitizen_doctor/ui/splash_ui.dart'; import 'package:device_info_plus/device_info_plus.dart'; +import 'package:starcitizen_doctor/widgets/widgets.dart'; import 'package:uuid/uuid.dart'; import 'package:window_manager/window_manager.dart'; @@ -23,6 +24,7 @@ import 'common/io/rs_http.dart'; import 'common/rust/frb_generated.dart'; import 'common/utils/base_utils.dart'; import 'data/app_version_data.dart'; +import 'ui/index_ui.dart'; import 'ui/settings/upgrade_dialog.dart'; part 'app.g.dart'; @@ -35,9 +37,13 @@ GoRouter router(RouterRef ref) { routes: [ GoRoute( path: '/', - builder: (context, state) { - return const SplashUI(); - }, + pageBuilder: (context, state) => + myPageBuilder(context, state, const SplashUI()), + ), + GoRoute( + path: '/index', + pageBuilder: (context, state) => + myPageBuilder(context, state, const IndexUI()), ), ], ); @@ -179,7 +185,7 @@ class AppGlobalModel extends _$AppGlobalModel { if (r != true) { if (!context.mounted) return false; - showToast(context, "获取更新信息失败,请稍后重试。"); + await showToast(context, "获取更新信息失败,请稍后重试。"); return false; } return true; diff --git a/lib/main.dart b/lib/main.dart index 9af9f5a..cab0b00 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -24,7 +24,6 @@ _initWindow() async { TitleBarStyle.hidden, windowButtonVisibility: false, ); - await windowManager.hide(); await windowManager.center(animate: true); } diff --git a/lib/ui/index_ui.dart b/lib/ui/index_ui.dart new file mode 100644 index 0000000..c37742f --- /dev/null +++ b/lib/ui/index_ui.dart @@ -0,0 +1,137 @@ +import 'package:fluent_ui/fluent_ui.dart'; +import 'package:flutter_hooks/flutter_hooks.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:starcitizen_doctor/common/conf/const_conf.dart'; +import 'package:starcitizen_doctor/widgets/widgets.dart'; +import 'package:window_manager/window_manager.dart'; + +class IndexUI extends HookConsumerWidget { + const IndexUI({super.key}); + + @override + Widget build(BuildContext context, WidgetRef ref) { + final curIndex = useState(0); + return NavigationView( + appBar: NavigationAppBar( + automaticallyImplyLeading: false, + title: () { + return DragToMoveArea( + child: Align( + alignment: AlignmentDirectional.centerStart, + child: Row( + children: [ + Image.asset( + "assets/app_logo_mini.png", + width: 20, + height: 20, + fit: BoxFit.cover, + ), + const SizedBox(width: 12), + const Text( + "SC汉化盒子 V${ConstConf.appVersion} ${ConstConf.isMSE ? "" : " Dev"}") + ], + ), + ), + ); + }(), + actions: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + IconButton( + icon: Stack( + children: [ + Padding( + padding: const EdgeInsets.all(6), + child: Icon( + FluentIcons.installation, + size: 22, + color: Colors.white.withOpacity(.6), + ), + ), + // if (model.aria2TotalTaskNum != 0) + // Positioned( + // bottom: 0, + // right: 0, + // child: Container( + // decoration: BoxDecoration( + // color: Colors.red, + // borderRadius: BorderRadius.circular(12), + // ), + // padding: const EdgeInsets.only( + // left: 6, right: 6, bottom: 1.5, top: 1.5), + // child: Text( + // "${model.aria2TotalTaskNum}", + // style: const TextStyle( + // fontSize: 8, + // color: Colors.white, + // ), + // ), + // )), + ], + ), + onPressed: () {}, + // onPressed: model.goDownloader + ), + const SizedBox(width: 24), + const WindowButtons() + ], + )), + pane: NavigationPane( + selected: curIndex.value, + items: getNavigationPaneItems(curIndex), + size: const NavigationPaneSize(openWidth: 64), + ), + paneBodyBuilder: (item, child) { + return FocusTraversalGroup( + key: ValueKey('body_$curIndex'), + child: getPage(curIndex.value), + ); + }, + ); + } + + Map get pageMenus => { + FluentIcons.home: "首页", + FluentIcons.game: "大厅", + FluentIcons.toolbox: "工具", + FluentIcons.settings: "设置", + FluentIcons.info: "关于", + }; + + List getNavigationPaneItems( + ValueNotifier curIndexState) { + return [ + for (final kv in pageMenus.entries) + PaneItem( + icon: Padding( + padding: const EdgeInsets.only(top: 6, bottom: 6, left: 4), + child: Column( + children: [ + Icon(kv.key, size: 18), + const SizedBox(height: 3), + Text( + kv.value, + style: const TextStyle(fontSize: 11), + ) + ], + ), + ), + // title: Text(kv.value), + body: const SizedBox.shrink(), + onTap: () => _onTapIndexMenu(kv.value, curIndexState), + ), + ]; + } + + Widget getPage(int value) { + return Center( + child: Text("$value"), + ); + } + + void _onTapIndexMenu(String value, ValueNotifier curIndexState) { + final pageIndex = + pageMenus.values.toList().indexWhere((element) => element == value); + curIndexState.value = pageIndex; + } +} diff --git a/lib/ui/settings/upgrade_dialog.dart b/lib/ui/settings/upgrade_dialog.dart index 9ff2439..4f030fa 100644 --- a/lib/ui/settings/upgrade_dialog.dart +++ b/lib/ui/settings/upgrade_dialog.dart @@ -143,12 +143,12 @@ class UpgradeDialogUI extends HookConsumerWidget { Future _getUpdateInfo( BuildContext context, - targetVersion, + String targetVersion, ValueNotifier description, ValueNotifier downloadUrl) async { try { final r = await Api.getAppReleaseDataByVersionName(targetVersion); - description = r["body"]; + description.value = r["body"]; final assets = List.of(r["assets"] ?? []); for (var asset in assets) { if (asset["name"].toString().endsWith("SETUP.exe")) { @@ -207,6 +207,7 @@ class UpgradeDialogUI extends HookConsumerWidget { } if (!context.mounted) return; _doCancel(context); + return; } isUpgrading.value = true; final fileName = "${appModel.getUpgradePath()}/next_SETUP.exe"; diff --git a/lib/ui/splash_ui.dart b/lib/ui/splash_ui.dart index 1c8443f..b964d53 100644 --- a/lib/ui/splash_ui.dart +++ b/lib/ui/splash_ui.dart @@ -1,11 +1,11 @@ import 'package:fluent_ui/fluent_ui.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; +import 'package:go_router/go_router.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:starcitizen_doctor/api/analytics.dart'; import 'package:starcitizen_doctor/app.dart'; import 'package:starcitizen_doctor/common/conf/const_conf.dart'; import 'package:starcitizen_doctor/common/conf/url_conf.dart'; -import 'package:starcitizen_doctor/common/io/aria2c.dart'; import 'package:starcitizen_doctor/common/utils/log.dart'; import 'package:starcitizen_doctor/provider/aria2c.dart'; import 'package:starcitizen_doctor/widgets/widgets.dart'; @@ -72,11 +72,7 @@ class SplashUI extends HookConsumerWidget { await appModel.checkUpdate(context); stepState.value = 2; ref.read(aria2cModelProvider); - // Navigator.pushAndRemoveUntil( - // context!, - // BaseUIContainer( - // uiCreate: () => IndexUI(), - // modelCreate: () => IndexUIModel()).makeRoute(context!), - // (route) => false); + if (!context.mounted) return; + context.go("/index"); } } diff --git a/lib/widgets/widgets.dart b/lib/widgets/widgets.dart index 76f4d3a..804f0e4 100644 --- a/lib/widgets/widgets.dart +++ b/lib/widgets/widgets.dart @@ -1,4 +1,5 @@ import 'package:fluent_ui/fluent_ui.dart'; +import 'package:go_router/go_router.dart'; import 'package:url_launcher/url_launcher_string.dart'; import 'package:window_manager/window_manager.dart'; import 'package:markdown_widget/config/all.dart'; @@ -97,3 +98,23 @@ List makeMarkdownView(String description, {String? attachmentsUrl}) { }) ])); } + +CustomTransitionPage myPageBuilder( + BuildContext context, GoRouterState state, Widget child) { + return CustomTransitionPage( + child: child, + transitionsBuilder: (BuildContext context, Animation animation, + Animation secondaryAnimation, Widget child) { + return Semantics( + scopesRoute: true, + explicitChildNodes: true, + child: EntrancePageTransition( + animation: CurvedAnimation( + parent: animation, + curve: FluentTheme.of(context).animationCurve, + ), + child: child, + ), + ); + }); +}