mod: 首页tab配置

This commit is contained in:
guozhigq
2023-08-11 17:32:16 +08:00
parent c55887af53
commit 5bf906b278
6 changed files with 92 additions and 90 deletions

View File

@ -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<LiveController>,
Get.find<RcmdController>,
Get.find<HotController>,
Get.find<BangumiController>,
];
late List tabsCtrList;
late List<Widget> 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<Widget>((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();
}

View File

@ -103,7 +103,7 @@ class _HomePageState extends State<HomePage>
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<HomePage>
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: