221 lines
6.7 KiB
Dart
221 lines
6.7 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:easy_refresh/easy_refresh.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:skywood/global/client/play_client.dart';
|
|
import 'package:skywood/main/lib_file.dart';
|
|
import 'package:skywood/pages/home/players/page/drama_detail_page.dart';
|
|
import 'package:skywood/pages/home/widgets/daily_quest_widget.dart';
|
|
import 'package:skywood/pages/home/widgets/home_cate_widget.dart';
|
|
import 'package:skywood/pages/home/widgets/hot_cartridge_widget.dart';
|
|
import 'package:skywood/pages/home/widgets/rank_list_widget.dart';
|
|
import 'package:skywood/pages/search/page/result_page.dart';
|
|
import 'package:skywood/pages/widgets/common_bg_page.dart';
|
|
import 'package:skywood/pages/widgets/mystery_box_widget.dart';
|
|
import 'package:skywood/utils/extend/gif_header.dart';
|
|
import 'package:skywood/utils/models/drama/skywood_category.dart';
|
|
import 'package:skywood/utils/models/drama/skywood_drama.dart';
|
|
import 'package:skywood/utils/models/drama/skywood_home.dart';
|
|
import 'package:skywood/utils/tools/app_toast.dart';
|
|
|
|
class HomePage extends StatefulWidget {
|
|
const HomePage({super.key});
|
|
|
|
@override
|
|
State<StatefulWidget> createState() {
|
|
return _MainRootState();
|
|
}
|
|
}
|
|
|
|
class _MainRootState extends State<HomePage> {
|
|
List<SkywoodHome> _homeData = [];
|
|
List<SkywoodCategory> _categories = [];
|
|
final EasyRefreshController _refreshController = EasyRefreshController(
|
|
controlFinishRefresh: true,
|
|
);
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
_refreshHome();
|
|
}
|
|
|
|
Future<void> _refreshHome() async {
|
|
// home_v3_recommand new_recommand week_ranking week_highest_recommend
|
|
// marquee home_banner get_details_recommand
|
|
AppToast.showLottieLoading();
|
|
final homeFuture = PlayClient.getHomeData();
|
|
final categoriesFuture = PlayClient.getCategoriesList();
|
|
final homeData = await homeFuture;
|
|
final categories = await categoriesFuture;
|
|
if (!mounted) return;
|
|
|
|
// for (SkywoodHome element in homeData) {
|
|
// print('lele: ${element.moduleKey} : ${element.dataList.length}');
|
|
// print('url: ${element.dataList.first.imageUrl}');
|
|
// }
|
|
|
|
|
|
_refreshController.finishRefresh();
|
|
AppToast.dismiss();
|
|
setState(() {
|
|
_homeData = homeData;
|
|
_categories = categories;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CommonBgPage(
|
|
child: SafeArea(
|
|
child: _homeData.isEmpty
|
|
? const SizedBox()
|
|
: _newBodyWidget(),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _newBodyWidget() {
|
|
return Column(
|
|
children: [
|
|
Container(
|
|
height: 204.h,
|
|
padding: EdgeInsets.only(left: 25.w, top: 3.h, right: 25.w),
|
|
child: HelpImg.asset(ConstImg.homeTopBg, fit: BoxFit.fill),
|
|
).addInkWell(onTap: () {
|
|
// 去到搜索页面
|
|
HelpNav.to(ResultPage(keyword: ''));
|
|
}),
|
|
const SizedBox(height: 10),
|
|
Expanded(child: EasyRefresh(
|
|
controller: _refreshController,
|
|
header: const GifHeader(),
|
|
onRefresh: _refreshHome,
|
|
child: _bodyWidget(),
|
|
))
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _bodyWidget() {
|
|
return CustomScrollView(
|
|
slivers: [
|
|
// _buildTopTwoImgs(),
|
|
// _buildSpace(),
|
|
_buildTitleImg(ConstImg.homeTitleDaily),
|
|
DailyQuestWidget(
|
|
dramaList: _homeData
|
|
.firstWhere((element) => element.moduleKey == 'home_v3_recommand')
|
|
.dataList,
|
|
),
|
|
_buildSpace(height: 10),
|
|
_buildTitleImg(ConstImg.homeTitleMystery),
|
|
_buildSpace(),
|
|
// 345 355
|
|
_buildTitleImg(
|
|
ConstImg.homeOpenNowBox,
|
|
padding: EdgeInsets.symmetric(horizontal: 15.w),
|
|
height: 355.h,
|
|
onTap: () {
|
|
// 随机获取一下视频 week_highest_recommend
|
|
List<SkywoodDrama> list = _homeData
|
|
.firstWhere((element) => element.moduleKey == 'week_highest_recommend')
|
|
.dataList;
|
|
int max = list.length;
|
|
int index = Random().nextInt(max);
|
|
HelpNav.showDialog(MysteryBoxWidget(
|
|
drama: list[index],
|
|
onTap: () {
|
|
HelpNav.to(DramaDetailPage(dramaBean: list[index]));
|
|
},
|
|
), barrierDismissible: true);
|
|
}
|
|
),
|
|
_buildSpace(height: 10),
|
|
_buildTitleImg(ConstImg.homeTitleHot),
|
|
_buildSpace(),
|
|
SliverPadding(
|
|
padding: EdgeInsets.symmetric(horizontal: 15.w),
|
|
sliver: HotCartridgeWidget(
|
|
dramaList: _homeData
|
|
.firstWhere((element) => element.moduleKey == 'new_recommand')
|
|
.dataList,
|
|
),
|
|
),
|
|
_buildSpace(height: 10),
|
|
_buildTitleImg(ConstImg.homeTitleWeekly),
|
|
SliverPadding(
|
|
padding: EdgeInsets.symmetric(horizontal: 15.w),
|
|
sliver: SliverToBoxAdapter(
|
|
child: RankListWidget(
|
|
dramaList: _homeData
|
|
.firstWhere((element) => element.moduleKey == 'week_ranking')
|
|
.dataList,
|
|
),
|
|
),
|
|
),
|
|
_buildTitleImg(ConstImg.homeTitleHotCate),
|
|
SliverPadding(
|
|
padding: EdgeInsets.only(left: 15.w, right: 15.w, top: 20.h),
|
|
sliver: SliverToBoxAdapter(
|
|
child: HomeCateWidget(categories: _categories),
|
|
),
|
|
),
|
|
_buildSpace(height: 20),
|
|
],
|
|
);
|
|
}
|
|
|
|
SliverToBoxAdapter _buildTopTwoImgs() {
|
|
// 104-76
|
|
return SliverToBoxAdapter(
|
|
child: Stack(
|
|
children: [
|
|
SizedBox(width: double.infinity, height: (204 + 104 - 28).h),
|
|
Container(
|
|
height: 204.h,
|
|
padding: EdgeInsets.only(left: 25.w, top: 3.h, right: 25.w),
|
|
child: HelpImg.asset(ConstImg.homeTopBg, fit: BoxFit.fill),
|
|
).addInkWell(onTap: () {
|
|
// 去到搜索页面
|
|
HelpNav.to(ResultPage(keyword: ''));
|
|
}),
|
|
Positioned(
|
|
top: (204 - 28).h,
|
|
height: 104.h,
|
|
width: AppScreen.screenWidth,
|
|
child: HelpImg.asset(ConstImg.homeTitleDaily, fit: BoxFit.fill),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
SliverToBoxAdapter _buildSpace({double height = 20}) {
|
|
return SliverToBoxAdapter(child: SizedBox(height: height.h));
|
|
}
|
|
|
|
SliverToBoxAdapter _buildTitleImg(
|
|
String imgName, {
|
|
double? height,
|
|
double? width,
|
|
Function()? onTap,
|
|
EdgeInsets? padding,
|
|
}) {
|
|
// 104-76
|
|
return SliverToBoxAdapter(
|
|
child: GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: onTap,
|
|
child: Container(
|
|
padding: padding ?? EdgeInsets.zero,
|
|
width: width ?? double.infinity,
|
|
height: height ?? 104.h,
|
|
child: HelpImg.asset(imgName, fit: BoxFit.fill),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|