mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-14 21:24:02 +08:00
@@ -1,26 +1,17 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
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';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:flutter/foundation.dart' show kDebugMode;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class HomeController extends GetxController
|
||||
with GetSingleTickerProviderStateMixin, ScrollOrRefreshMixin {
|
||||
late List<HomeTabType> tabs;
|
||||
late TabController tabController;
|
||||
|
||||
RxBool? showTopBar;
|
||||
late final bool hideTopBar;
|
||||
|
||||
ScrollOrRefreshMixin get controller => tabs[tabController.index].ctr();
|
||||
ScrollOrRefreshMixin get controller =>
|
||||
HomeTabType.values[tabController.index].ctr();
|
||||
|
||||
@override
|
||||
ScrollController get scrollController => controller.scrollController;
|
||||
@@ -30,41 +21,16 @@ class HomeController extends GetxController
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
hideTopBar = Pref.hideTopBar;
|
||||
if (hideTopBar) {
|
||||
final mainCtr = Get.find<MainController>();
|
||||
switch (mainCtr.barHideType) {
|
||||
case .instant:
|
||||
showTopBar = RxBool(true);
|
||||
case .sync:
|
||||
mainCtr.barOffset ??= RxDouble(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
setTabConfig();
|
||||
tabController = TabController(
|
||||
initialIndex: HomeTabType.rcmd.index,
|
||||
length: HomeTabType.values.length,
|
||||
vsync: this,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onRefresh() {
|
||||
return controller.onRefresh().catchError((e) {
|
||||
if (kDebugMode) debugPrint(e.toString());
|
||||
});
|
||||
}
|
||||
|
||||
void setTabConfig() {
|
||||
final tabs = GStorage.setting.get(SettingBoxKey.tabBarSort) as List?;
|
||||
if (tabs != null) {
|
||||
this.tabs = tabs.map((i) => HomeTabType.values[i]).toList();
|
||||
} else {
|
||||
this.tabs = HomeTabType.values;
|
||||
}
|
||||
|
||||
tabController = TabController(
|
||||
initialIndex: max(0, this.tabs.indexOf(HomeTabType.rcmd)),
|
||||
length: this.tabs.length,
|
||||
vsync: this,
|
||||
);
|
||||
return controller.onRefresh();
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import 'package:PiliPlus/common/style.dart';
|
||||
import 'package:PiliPlus/common/widgets/custom_height_widget.dart';
|
||||
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
||||
import 'package:PiliPlus/common/widgets/scroll_physics.dart';
|
||||
import 'package:PiliPlus/pages/common/common_page.dart';
|
||||
import 'package:PiliPlus/models/common/home_tab_type.dart';
|
||||
import 'package:PiliPlus/pages/home/controller.dart';
|
||||
import 'package:PiliPlus/pages/main/controller.dart';
|
||||
import 'package:PiliPlus/pages/mine/controller.dart';
|
||||
import 'package:PiliPlus/utils/extension/get_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/size_ext.dart';
|
||||
import 'package:flutter/foundation.dart' show kDebugMode;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
||||
@@ -19,14 +19,11 @@ class HomePage extends StatefulWidget {
|
||||
State<HomePage> createState() => _HomePageState();
|
||||
}
|
||||
|
||||
class _HomePageState extends CommonPageState<HomePage>
|
||||
class _HomePageState extends State<HomePage>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
final _homeController = Get.putOrFind(HomeController.new);
|
||||
final _mainController = Get.find<MainController>();
|
||||
|
||||
@override
|
||||
bool get needsCorrection => _homeController.hideTopBar;
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
@@ -34,51 +31,36 @@ class _HomePageState extends CommonPageState<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: Style.mdRadius,
|
||||
tabAlignment: TabAlignment.center,
|
||||
onTap: (_) {
|
||||
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 (MediaQuery.sizeOf(context).isPortrait) customAppBar(theme),
|
||||
tabBar,
|
||||
Expanded(
|
||||
child: onBuild(
|
||||
tabBarView(
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: SizedBox(
|
||||
height: 42,
|
||||
width: double.infinity,
|
||||
child: TabBar(
|
||||
controller: _homeController.tabController,
|
||||
children: _homeController.tabs.map((e) => e.page).toList(),
|
||||
tabs: HomeTabType.values.map((e) => Tab(text: e.label)).toList(),
|
||||
isScrollable: true,
|
||||
dividerColor: Colors.transparent,
|
||||
dividerHeight: 0,
|
||||
splashBorderRadius: Style.mdRadius,
|
||||
tabAlignment: TabAlignment.center,
|
||||
onTap: (_) {
|
||||
if (!_homeController.tabController.indexIsChanging) {
|
||||
_homeController.animateToTop();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: tabBarView(
|
||||
controller: _homeController.tabController,
|
||||
children: HomeTabType.values.map((e) => e.page).toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -94,39 +76,6 @@ class _HomePageState extends CommonPageState<HomePage>
|
||||
userAvatar(theme: theme, mainController: _mainController),
|
||||
],
|
||||
);
|
||||
if (_homeController.hideTopBar) {
|
||||
if (_mainController.barOffset case final barOffset?) {
|
||||
return Obx(
|
||||
() {
|
||||
final offset = barOffset.value;
|
||||
return CustomHeightWidget(
|
||||
offset: Offset(0, -offset),
|
||||
height: Style.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 ? Style.topBarHeight : 0,
|
||||
padding: padding,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
return Container(
|
||||
height: Style.topBarHeight,
|
||||
padding: padding,
|
||||
@@ -246,7 +195,7 @@ Widget userAvatar({
|
||||
Widget msgBadge(MainController mainController) {
|
||||
return Obx(
|
||||
() {
|
||||
if (mainController.accountService.isLogin.value) {
|
||||
if (mainController.accountService.isLogin.value || kDebugMode) {
|
||||
final count = mainController.msgUnReadCount.value;
|
||||
final isNumBadge = mainController.msgBadgeMode == .number;
|
||||
return IconButton(
|
||||
|
||||
Reference in New Issue
Block a user