feat: 首页tabbar样式设置 issues #564
This commit is contained in:
@ -26,6 +26,7 @@ class HomeController extends GetxController with GetTickerProviderStateMixin {
|
|||||||
late List defaultTabs;
|
late List defaultTabs;
|
||||||
late List<String> tabbarSort;
|
late List<String> tabbarSort;
|
||||||
RxString defaultSearch = ''.obs;
|
RxString defaultSearch = ''.obs;
|
||||||
|
late bool enableGradientBg;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@ -40,6 +41,8 @@ class HomeController extends GetxController with GetTickerProviderStateMixin {
|
|||||||
if (setting.get(SettingBoxKey.enableSearchWord, defaultValue: true)) {
|
if (setting.get(SettingBoxKey.enableSearchWord, defaultValue: true)) {
|
||||||
searchDefault();
|
searchDefault();
|
||||||
}
|
}
|
||||||
|
enableGradientBg =
|
||||||
|
setting.get(SettingBoxKey.enableGradientBg, defaultValue: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onRefresh() {
|
void onRefresh() {
|
||||||
|
|||||||
@ -48,17 +48,20 @@ class _HomePageState extends State<HomePage>
|
|||||||
super.build(context);
|
super.build(context);
|
||||||
Brightness currentBrightness = MediaQuery.of(context).platformBrightness;
|
Brightness currentBrightness = MediaQuery.of(context).platformBrightness;
|
||||||
// 设置状态栏图标的亮度
|
// 设置状态栏图标的亮度
|
||||||
|
if (_homeController.enableGradientBg) {
|
||||||
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
||||||
statusBarIconBrightness: currentBrightness == Brightness.light
|
statusBarIconBrightness: currentBrightness == Brightness.light
|
||||||
? Brightness.dark
|
? Brightness.dark
|
||||||
: Brightness.light,
|
: Brightness.light,
|
||||||
));
|
));
|
||||||
|
}
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
extendBody: true,
|
extendBody: true,
|
||||||
extendBodyBehindAppBar: true,
|
extendBodyBehindAppBar: true,
|
||||||
body: Stack(
|
body: Stack(
|
||||||
children: [
|
children: [
|
||||||
// gradient background
|
// gradient background
|
||||||
|
if (_homeController.enableGradientBg) ...[
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.topLeft,
|
alignment: Alignment.topLeft,
|
||||||
child: Opacity(
|
child: Opacity(
|
||||||
@ -69,8 +72,14 @@ class _HomePageState extends State<HomePage>
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
gradient: LinearGradient(
|
gradient: LinearGradient(
|
||||||
colors: [
|
colors: [
|
||||||
Theme.of(context).colorScheme.primary.withOpacity(0.9),
|
Theme.of(context)
|
||||||
Theme.of(context).colorScheme.primary.withOpacity(0.5),
|
.colorScheme
|
||||||
|
.primary
|
||||||
|
.withOpacity(0.9),
|
||||||
|
Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.primary
|
||||||
|
.withOpacity(0.5),
|
||||||
Theme.of(context).colorScheme.surface
|
Theme.of(context).colorScheme.surface
|
||||||
],
|
],
|
||||||
begin: Alignment.topLeft,
|
begin: Alignment.topLeft,
|
||||||
@ -80,6 +89,7 @@ class _HomePageState extends State<HomePage>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
],
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
CustomAppBar(
|
CustomAppBar(
|
||||||
@ -90,7 +100,37 @@ class _HomePageState extends State<HomePage>
|
|||||||
callback: showUserBottomSheet,
|
callback: showUserBottomSheet,
|
||||||
),
|
),
|
||||||
if (_homeController.tabs.length > 1) ...[
|
if (_homeController.tabs.length > 1) ...[
|
||||||
|
if (_homeController.enableGradientBg) ...[
|
||||||
const CustomTabs(),
|
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 ...[
|
] else ...[
|
||||||
const SizedBox(height: 6),
|
const SizedBox(height: 6),
|
||||||
],
|
],
|
||||||
|
|||||||
@ -102,6 +102,12 @@ class _StyleSettingState extends State<StyleSetting> {
|
|||||||
defaultVal: true,
|
defaultVal: true,
|
||||||
needReboot: true,
|
needReboot: true,
|
||||||
),
|
),
|
||||||
|
const SetSwitchItem(
|
||||||
|
title: '首页底栏背景渐变',
|
||||||
|
setKey: SettingBoxKey.enableGradientBg,
|
||||||
|
defaultVal: true,
|
||||||
|
needReboot: true,
|
||||||
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
int? result = await showDialog(
|
int? result = await showDialog(
|
||||||
|
|||||||
@ -135,7 +135,8 @@ class SettingBoxKey {
|
|||||||
hideSearchBar = 'hideSearchBar', // 收起顶栏
|
hideSearchBar = 'hideSearchBar', // 收起顶栏
|
||||||
hideTabBar = 'hideTabBar', // 收起底栏
|
hideTabBar = 'hideTabBar', // 收起底栏
|
||||||
tabbarSort = 'tabbarSort', // 首页tabbar
|
tabbarSort = 'tabbarSort', // 首页tabbar
|
||||||
dynamicBadgeMode = 'dynamicBadgeMode';
|
dynamicBadgeMode = 'dynamicBadgeMode',
|
||||||
|
enableGradientBg = 'enableGradientBg';
|
||||||
}
|
}
|
||||||
|
|
||||||
class LocalCacheKey {
|
class LocalCacheKey {
|
||||||
|
|||||||
Reference in New Issue
Block a user