From 02cc1646359ad032c0088874c7779009aa41613d Mon Sep 17 00:00:00 2001 From: guozhigq Date: Fri, 23 Feb 2024 22:44:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A6=96=E9=A1=B5tabbar=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E8=AE=BE=E7=BD=AE=20issues=20#564?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/home/controller.dart | 3 + lib/pages/home/view.dart | 88 ++++++++++++++++++++-------- lib/pages/setting/style_setting.dart | 6 ++ lib/utils/storage.dart | 3 +- 4 files changed, 75 insertions(+), 25 deletions(-) diff --git a/lib/pages/home/controller.dart b/lib/pages/home/controller.dart index 685ff5c3..9f6f8ac5 100644 --- a/lib/pages/home/controller.dart +++ b/lib/pages/home/controller.dart @@ -26,6 +26,7 @@ class HomeController extends GetxController with GetTickerProviderStateMixin { late List defaultTabs; late List tabbarSort; RxString defaultSearch = ''.obs; + late bool enableGradientBg; @override void onInit() { @@ -40,6 +41,8 @@ class HomeController extends GetxController with GetTickerProviderStateMixin { if (setting.get(SettingBoxKey.enableSearchWord, defaultValue: true)) { searchDefault(); } + enableGradientBg = + setting.get(SettingBoxKey.enableGradientBg, defaultValue: true); } void onRefresh() { diff --git a/lib/pages/home/view.dart b/lib/pages/home/view.dart index ce7b46c6..91d0ea8c 100644 --- a/lib/pages/home/view.dart +++ b/lib/pages/home/view.dart @@ -48,38 +48,48 @@ class _HomePageState extends State super.build(context); Brightness currentBrightness = MediaQuery.of(context).platformBrightness; // 设置状态栏图标的亮度 - SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( - statusBarIconBrightness: currentBrightness == Brightness.light - ? Brightness.dark - : Brightness.light, - )); + if (_homeController.enableGradientBg) { + SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( + statusBarIconBrightness: currentBrightness == Brightness.light + ? Brightness.dark + : Brightness.light, + )); + } return Scaffold( extendBody: true, extendBodyBehindAppBar: true, body: Stack( children: [ // gradient background - Align( - alignment: Alignment.topLeft, - child: Opacity( - opacity: 0.6, - child: Container( - width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.height, - decoration: BoxDecoration( - gradient: LinearGradient( - colors: [ - Theme.of(context).colorScheme.primary.withOpacity(0.9), - Theme.of(context).colorScheme.primary.withOpacity(0.5), - Theme.of(context).colorScheme.surface - ], - begin: Alignment.topLeft, - end: Alignment.bottomRight, - stops: const [0, 0.0034, 0.34]), + if (_homeController.enableGradientBg) ...[ + Align( + alignment: Alignment.topLeft, + child: Opacity( + opacity: 0.6, + child: Container( + width: MediaQuery.of(context).size.width, + height: MediaQuery.of(context).size.height, + decoration: BoxDecoration( + gradient: LinearGradient( + colors: [ + Theme.of(context) + .colorScheme + .primary + .withOpacity(0.9), + Theme.of(context) + .colorScheme + .primary + .withOpacity(0.5), + Theme.of(context).colorScheme.surface + ], + begin: Alignment.topLeft, + end: Alignment.bottomRight, + stops: const [0, 0.0034, 0.34]), + ), ), ), ), - ), + ], Column( children: [ CustomAppBar( @@ -90,7 +100,37 @@ class _HomePageState extends State callback: showUserBottomSheet, ), if (_homeController.tabs.length > 1) ...[ - const CustomTabs(), + if (_homeController.enableGradientBg) ...[ + const CustomTabs(), + ] else ...[ + const SizedBox(height: 4), + SizedBox( + width: double.infinity, + height: 42, + child: Align( + alignment: Alignment.center, + child: TabBar( + controller: _homeController.tabController, + tabs: [ + for (var i in _homeController.tabs) + Tab(text: i['label']) + ], + isScrollable: true, + dividerColor: Colors.transparent, + enableFeedback: true, + splashBorderRadius: BorderRadius.circular(10), + tabAlignment: TabAlignment.center, + onTap: (value) { + feedBack(); + if (_homeController.initialIndex.value == value) { + _homeController.tabsCtrList[value]().animateToTop(); + } + _homeController.initialIndex.value = value; + }, + ), + ), + ), + ], ] else ...[ const SizedBox(height: 6), ], diff --git a/lib/pages/setting/style_setting.dart b/lib/pages/setting/style_setting.dart index fb3c780a..c9bffa69 100644 --- a/lib/pages/setting/style_setting.dart +++ b/lib/pages/setting/style_setting.dart @@ -102,6 +102,12 @@ class _StyleSettingState extends State { defaultVal: true, needReboot: true, ), + const SetSwitchItem( + title: '首页底栏背景渐变', + setKey: SettingBoxKey.enableGradientBg, + defaultVal: true, + needReboot: true, + ), ListTile( onTap: () async { int? result = await showDialog( diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 41ec0ce8..16cef463 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -135,7 +135,8 @@ class SettingBoxKey { hideSearchBar = 'hideSearchBar', // 收起顶栏 hideTabBar = 'hideTabBar', // 收起底栏 tabbarSort = 'tabbarSort', // 首页tabbar - dynamicBadgeMode = 'dynamicBadgeMode'; + dynamicBadgeMode = 'dynamicBadgeMode', + enableGradientBg = 'enableGradientBg'; } class LocalCacheKey {