add bar hide type

Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-02-18 21:12:34 +08:00
parent a142b15344
commit 3f3d54fd27
12 changed files with 223 additions and 63 deletions

View File

@@ -5,6 +5,7 @@ import 'package:PiliPlus/http/api.dart';
import 'package:PiliPlus/http/init.dart';
import 'package:PiliPlus/models/common/home_tab_type.dart';
import 'package:PiliPlus/pages/common/common_controller.dart';
import 'package:PiliPlus/pages/main/controller.dart';
import 'package:PiliPlus/services/account_service.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:PiliPlus/utils/storage_key.dart';
@@ -19,7 +20,8 @@ class HomeController extends GetxController
late List<HomeTabType> tabs;
late TabController tabController;
final bool hideTopBar = !Pref.useSideBar && Pref.hideTopBar;
RxBool? showTopBar;
late final bool hideTopBar;
bool enableSearchWord = Pref.enableSearchWord;
late final RxString defaultSearch = ''.obs;
@@ -36,6 +38,17 @@ class HomeController extends GetxController
void onInit() {
super.onInit();
hideTopBar = !Pref.useSideBar && Pref.hideTopBar;
if (hideTopBar) {
final mainCtr = Get.find<MainController>();
switch (mainCtr.barHideType) {
case .instant:
showTopBar = RxBool(true);
case .sync:
mainCtr.barOffset ??= RxDouble(0.0);
}
}
if (enableSearchWord) {
lateCheckSearchAt = DateTime.now().millisecondsSinceEpoch;
querySearchDefault();

View File

@@ -31,38 +31,46 @@ class _HomePageState extends State<HomePage>
Widget build(BuildContext context) {
super.build(context);
final theme = Theme.of(context);
Widget tabBar;
if (_homeController.tabs.length > 1) {
tabBar = Padding(
padding: const EdgeInsets.only(top: 4),
child: SizedBox(
height: 42,
width: double.infinity,
child: TabBar(
controller: _homeController.tabController,
tabs: _homeController.tabs.map((e) => Tab(text: e.label)).toList(),
isScrollable: true,
dividerColor: Colors.transparent,
dividerHeight: 0,
splashBorderRadius: StyleString.mdRadius,
tabAlignment: TabAlignment.center,
onTap: (_) {
feedBack();
if (!_homeController.tabController.indexIsChanging) {
_homeController.animateToTop();
}
},
),
),
);
if (_homeController.hideTopBar &&
_mainController.barHideType == .instant) {
tabBar = Material(
color: theme.colorScheme.surface,
child: tabBar,
);
}
} else {
tabBar = const SizedBox(height: 6);
}
return Column(
children: [
if (!_mainController.useSideBar &&
MediaQuery.sizeOf(context).isPortrait)
customAppBar(theme),
if (_homeController.tabs.length > 1)
Padding(
padding: const EdgeInsets.only(top: 4),
child: SizedBox(
height: 42,
width: double.infinity,
child: TabBar(
controller: _homeController.tabController,
tabs: _homeController.tabs
.map((e) => Tab(text: e.label))
.toList(),
isScrollable: true,
dividerColor: Colors.transparent,
dividerHeight: 0,
splashBorderRadius: StyleString.mdRadius,
tabAlignment: TabAlignment.center,
onTap: (_) {
feedBack();
if (!_homeController.tabController.indexIsChanging) {
_homeController.animateToTop();
}
},
),
),
)
else
const SizedBox(height: 6),
tabBar,
Expanded(
child: tabBarView(
controller: _homeController.tabController,
@@ -85,26 +93,43 @@ class _HomePageState extends State<HomePage>
],
);
if (_homeController.hideTopBar) {
return Obx(
() {
final barOffset = _mainController.barOffset!.value;
return CustomHeightWidget(
offset: Offset(0, -barOffset),
height: StyleString.topBarHeight - barOffset,
child: Padding(
if (_mainController.barOffset case final barOffset?) {
return Obx(
() {
final offset = barOffset.value;
return CustomHeightWidget(
offset: Offset(0, -offset),
height: StyleString.topBarHeight - offset,
child: Padding(
padding: padding,
child: child,
),
);
},
);
}
if (_homeController.showTopBar case final showTopBar?) {
return Obx(() {
final showSearchBar = showTopBar.value;
return AnimatedOpacity(
opacity: showSearchBar ? 1 : 0,
duration: const Duration(milliseconds: 300),
child: AnimatedContainer(
curve: Curves.easeInOutCubicEmphasized,
duration: const Duration(milliseconds: 500),
height: showSearchBar ? StyleString.topBarHeight : 0,
padding: padding,
child: child,
),
);
},
);
} else {
return Container(
height: StyleString.topBarHeight,
padding: padding,
child: child,
);
});
}
}
return Container(
height: StyleString.topBarHeight,
padding: padding,
child: child,
);
}
Widget searchBar(ThemeData theme) {