diff --git a/lib/common/widgets/network_img_layer.dart b/lib/common/widgets/network_img_layer.dart index 41cad46e..46683e96 100644 --- a/lib/common/widgets/network_img_layer.dart +++ b/lib/common/widgets/network_img_layer.dart @@ -37,8 +37,6 @@ class NetworkImgLayer extends StatelessWidget { int picQuality = setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10); // double pr = 2; - print( - '${src!.startsWith('//') ? 'https:${src!}' : src!}@${quality ?? picQuality}q.webp'); return src != '' ? ClipRRect( clipBehavior: Clip.hardEdge, diff --git a/lib/models/common/tab_type.dart b/lib/models/common/tab_type.dart new file mode 100644 index 00000000..90d19029 --- /dev/null +++ b/lib/models/common/tab_type.dart @@ -0,0 +1,55 @@ +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:pilipala/pages/bangumi/index.dart'; +import 'package:pilipala/pages/hot/index.dart'; +import 'package:pilipala/pages/live/index.dart'; +import 'package:pilipala/pages/rcmd/index.dart'; + +enum TabType { live, rcmd, hot, bangumi } + +extension TabTypeDesc on TabType { + String get description => ['直播', '推荐', '热门', '番剧'][index]; +} + +List tabsConfig = [ + { + 'icon': const Icon( + Icons.live_tv_outlined, + size: 15, + ), + 'label': '直播', + 'type': TabType.live, + 'ctr': Get.find, + 'page': const LivePage(), + }, + { + 'icon': const Icon( + Icons.thumb_up_off_alt_outlined, + size: 15, + ), + 'label': '推荐', + 'type': TabType.rcmd, + 'ctr': Get.find, + 'page': const RcmdPage(), + }, + { + 'icon': const Icon( + Icons.whatshot_outlined, + size: 15, + ), + 'label': '热门', + 'type': TabType.hot, + 'ctr': Get.find, + 'page': const HotPage(), + }, + { + 'icon': const Icon( + Icons.play_circle_outlined, + size: 15, + ), + 'label': '番剧', + 'type': TabType.bangumi, + 'ctr': Get.find, + 'page': const BangumiPage(), + }, +]; diff --git a/lib/pages/home/controller.dart b/lib/pages/home/controller.dart index 67cbf202..f5ce88ac 100644 --- a/lib/pages/home/controller.dart +++ b/lib/pages/home/controller.dart @@ -2,56 +2,16 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:hive/hive.dart'; import 'package:pilipala/http/index.dart'; -import 'package:pilipala/pages/bangumi/index.dart'; -import 'package:pilipala/pages/hot/index.dart'; -import 'package:pilipala/pages/live/index.dart'; -import 'package:pilipala/pages/rcmd/index.dart'; +import 'package:pilipala/models/common/tab_type.dart'; import 'package:pilipala/utils/storage.dart'; class HomeController extends GetxController with GetTickerProviderStateMixin { bool flag = false; - List tabs = [ - { - 'icon': const Icon( - Icons.live_tv_outlined, - size: 15, - ), - 'label': '直播', - 'type': 'live' - }, - { - 'icon': const Icon( - Icons.thumb_up_off_alt_outlined, - size: 15, - ), - 'label': '推荐', - 'type': 'rcm' - }, - { - 'icon': const Icon( - Icons.whatshot_outlined, - size: 15, - ), - 'label': '热门', - 'type': 'hot' - }, - { - 'icon': const Icon( - Icons.play_circle_outlined, - size: 15, - ), - 'label': '番剧', - 'type': 'bangumi' - }, - ]; + late List tabs; int initialIndex = 1; late TabController tabController; - List ctrList = [ - Get.find, - Get.find, - Get.find, - Get.find, - ]; + late List tabsCtrList; + late List tabsPageList; RxString defaultSearch = '输入关键词搜索'.obs; Box user = GStrorage.user; RxBool userLogin = false.obs; @@ -60,25 +20,32 @@ class HomeController extends GetxController with GetTickerProviderStateMixin { @override void onInit() { super.onInit(); + + searchDefault(); + userLogin.value = user.get(UserBoxKey.userLogin) ?? false; + userFace.value = user.get(UserBoxKey.userFace) ?? ''; + + // 进行tabs配置 + tabs = tabsConfig; + tabsCtrList = tabsConfig.map((e) => e['ctr']).toList(); + tabsPageList = tabsConfig.map((e) => e['page']).toList(); + tabController = TabController( initialIndex: initialIndex, length: tabs.length, vsync: this, ); - searchDefault(); - userLogin.value = user.get(UserBoxKey.userLogin) ?? false; - userFace.value = user.get(UserBoxKey.userFace) ?? ''; } void onRefresh() { int index = tabController.index; - var ctr = ctrList[index]; + var ctr = tabsCtrList[index]; ctr().onRefresh(); } void animateToTop() { int index = tabController.index; - var ctr = ctrList[index]; + var ctr = tabsCtrList[index]; ctr().animateToTop(); } diff --git a/lib/pages/home/view.dart b/lib/pages/home/view.dart index 73e1272f..447d9628 100644 --- a/lib/pages/home/view.dart +++ b/lib/pages/home/view.dart @@ -103,7 +103,7 @@ class _HomePageState extends State onTap: (value) { feedBack(); if (_homeController.initialIndex == value) { - _homeController.ctrList[value]().animateToTop(); + _homeController.tabsCtrList[value]().animateToTop(); } _homeController.initialIndex = value; }, @@ -134,12 +134,7 @@ class _HomePageState extends State Expanded( child: TabBarView( controller: _homeController.tabController, - children: const [ - LivePage(), - RcmdPage(), - HotPage(), - BangumiPage(), - ], + children: _homeController.tabsPageList, ), ), ], @@ -179,25 +174,15 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { child: AnimatedContainer( curve: Curves.linear, duration: const Duration(milliseconds: 300), - height: snapshot.data ? 94 : MediaQuery.of(context).padding.top, + height: snapshot.data ? 96 : MediaQuery.of(context).padding.top, child: Container( padding: EdgeInsets.only( - left: 12, + left: 14, right: 12, bottom: 4, top: MediaQuery.of(context).padding.top, ), child: Row(children: [ - const Text( - 'PLPL', - style: TextStyle( - height: 2.8, - fontSize: 17, - fontWeight: FontWeight.bold, - fontFamily: 'Jura-Bold', - ), - ), - const SizedBox(width: 10), Expanded( child: GestureDetector( onTap: () { @@ -206,7 +191,7 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { }, child: Container( width: 250, - height: 42, + height: 44, clipBehavior: Clip.hardEdge, padding: const EdgeInsets.only(left: 12, right: 22), decoration: BoxDecoration( @@ -241,33 +226,20 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { ), ), const SizedBox(width: 10), - // SizedBox( - // width: 36, - // height: 36, - // child: IconButton( - // style: ButtonStyle( - // padding: MaterialStateProperty.all(EdgeInsets.zero), - // ), - // onPressed: () {}, - // icon: const Icon(Icons.notifications_none_outlined, - // size: 22), - // ), - // ), - // const SizedBox(width: 8), Obx( () => ctr!.userLogin.value ? GestureDetector( onTap: () => callback!(), child: NetworkImgLayer( type: 'avatar', - width: 34, - height: 34, + width: 38, + height: 38, src: ctr!.userFace.value, ), ) : SizedBox( - width: 36, - height: 36, + width: 38, + height: 38, child: IconButton( style: ButtonStyle( padding: diff --git a/lib/pages/main/view.dart b/lib/pages/main/view.dart index 4b5a0bd2..4cec9ac8 100644 --- a/lib/pages/main/view.dart +++ b/lib/pages/main/view.dart @@ -142,7 +142,8 @@ class _MainAppState extends State with SingleTickerProviderStateMixin { currentIndex: selectedIndex, // type: BottomNavigationBarType.shifting, selectedItemColor: Theme.of(context).colorScheme.primary, - unselectedItemColor: Theme.of(context).colorScheme.outline, + unselectedItemColor: + Theme.of(context).colorScheme.outline.withOpacity(0.5), selectedFontSize: 12.4, onTap: (value) => setIndex(value), items: [ diff --git a/lib/pages/mine/view.dart b/lib/pages/mine/view.dart index f991c3a2..102e47bf 100644 --- a/lib/pages/mine/view.dart +++ b/lib/pages/mine/view.dart @@ -23,7 +23,16 @@ class MinePage extends StatelessWidget { elevation: 0, toolbarHeight: kTextTabBarHeight + 20, backgroundColor: Colors.transparent, - title: null, + centerTitle: false, + title: const Text( + 'PLPL', + style: TextStyle( + height: 2.8, + fontSize: 17, + fontWeight: FontWeight.bold, + fontFamily: 'Jura-Bold', + ), + ), actions: [ IconButton( onPressed: () => mineController.onChangeTheme(),