429 lines
16 KiB
Dart
429 lines
16 KiB
Dart
import 'dart:async';
|
|
import 'dart:ui';
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:carousel_slider/carousel_slider.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:game/dialog/sign_dialog.dart';
|
|
import 'package:game/network/NetworkConfig.dart';
|
|
|
|
import '../../beans/epg_bean.dart';
|
|
import '../../beans/home_info_bean.dart';
|
|
import '../../beans/home_ranking_bean.dart';
|
|
import '../../beans/sign_bean.dart';
|
|
import '../../common/func.dart';
|
|
import 'home_ranking_page.dart';
|
|
import 'home_recommend_page.dart';
|
|
import 'my_home_model.dart';
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
const MyHomePage({super.key});
|
|
|
|
@override
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
}
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
|
List<EpgBean> bannerList = [];
|
|
List<HomeInfoBean> homeInfoList = [];
|
|
|
|
int currentBannerIndex = 0; //banner下标
|
|
|
|
int pageIndex = 0; // 0推荐 1历史
|
|
|
|
late StreamSubscription subscription;
|
|
final MyHomeModel _viewModel = MyHomeModel();
|
|
|
|
List<HomeRankingBean> rankingList = [];
|
|
late SignBean signBean;
|
|
int unreadNum = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
|
|
subscription = _viewModel.streamController.stream.listen((event) {
|
|
String code = event['code'];
|
|
if (code.isNotEmpty) {
|
|
switch (code) {
|
|
case "getHomeInfo":
|
|
List<HomeInfoBean> data = event['data'];
|
|
|
|
for (int i = 0; i < data.length; i++) {
|
|
///banner数据
|
|
if (data[i].categoryName == "Banner") {
|
|
bannerList = data[i].epgList!;
|
|
print("bannerList==${bannerList.length}");
|
|
} else {
|
|
homeInfoList.add(data[i]);
|
|
}
|
|
}
|
|
break;
|
|
|
|
case "getGameRankingList":
|
|
rankingList = event['data'];
|
|
break;
|
|
|
|
case "getSevenSignList":
|
|
signBean = event['data'];
|
|
if (!signBean.isSign!) {
|
|
FunctionUtil.popDialog2(
|
|
context,
|
|
SignDialog(
|
|
list: signBean.list!,
|
|
onTap: () {
|
|
EasyLoading.show(status: "加载中");
|
|
_viewModel.sevenSignToday();
|
|
},
|
|
));
|
|
}
|
|
break;
|
|
|
|
case "sevenSignToday": //签到
|
|
EasyLoading.showToast(event['data']);
|
|
_viewModel.getSevenSignList();
|
|
_viewModel.getUserInfo();
|
|
break;
|
|
|
|
case "getUserMessageNotReadCount":
|
|
unreadNum = event['data'];
|
|
break;
|
|
}
|
|
setState(() {});
|
|
}
|
|
});
|
|
_viewModel.getHomeInfo();
|
|
_viewModel.getGameRankingList();
|
|
if (NetworkConfig.token != "") {
|
|
_viewModel.getSevenSignList();
|
|
_viewModel.getUserMessageNotReadCount();
|
|
_viewModel.getUserInfo();
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
// TODO: implement dispose
|
|
subscription.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final size = MediaQuery.of(context).size;
|
|
|
|
return Scaffold(
|
|
backgroundColor: Color(0xFF17181A),
|
|
body: Stack(
|
|
children: [
|
|
SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
width: size.width,
|
|
height: 387,
|
|
color: const Color(0xFFA4A4A4),
|
|
child: Stack(
|
|
children: [
|
|
///banner
|
|
Container(
|
|
child: CarouselSlider(
|
|
options: CarouselOptions(
|
|
height: 387,
|
|
autoPlay: true,
|
|
viewportFraction: 1,
|
|
onPageChanged: (index, _) {
|
|
setState(() {
|
|
currentBannerIndex = index;
|
|
});
|
|
}),
|
|
items: _bannerItem(),
|
|
),
|
|
),
|
|
|
|
///banner标题
|
|
Positioned(
|
|
bottom: 0,
|
|
child: Container(
|
|
width: size.width,
|
|
height: 88,
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [
|
|
Color(0x0017181A),
|
|
Color(0xFF17181A),
|
|
],
|
|
),
|
|
),
|
|
child: Stack(
|
|
children: [
|
|
Positioned(
|
|
left: 15,
|
|
top: 13,
|
|
child: bannerList.isNotEmpty
|
|
? Text(
|
|
"${bannerList[currentBannerIndex].title}",
|
|
style: TextStyle(color: Colors.white, fontSize: 21),
|
|
)
|
|
: Container()),
|
|
Positioned(
|
|
left: 15,
|
|
bottom: 21,
|
|
child: bannerList.isNotEmpty
|
|
? Text(
|
|
"${bannerList[currentBannerIndex].subTitle}",
|
|
style: TextStyle(color: Colors.white, fontSize: 13),
|
|
)
|
|
: Container()),
|
|
|
|
///banner指示器
|
|
Positioned(
|
|
top: 9,
|
|
right: 14,
|
|
child: Row(
|
|
children: List.generate(
|
|
bannerList.length,
|
|
(index) => Container(
|
|
width: 4,
|
|
height: 4,
|
|
margin: EdgeInsets.only(left: 7),
|
|
decoration: BoxDecoration(
|
|
color: Color(currentBannerIndex == index ? 0xFFFFFFFF : 0x99FFFFFF),
|
|
borderRadius: BorderRadius.all(Radius.circular(10))),
|
|
)),
|
|
))
|
|
],
|
|
),
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
|
|
///推荐 - 游玩历史
|
|
Container(
|
|
width: size.width,
|
|
height: 50,
|
|
margin: EdgeInsets.only(left: 14, right: 14),
|
|
child: Row(
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () {
|
|
setState(() {
|
|
pageIndex = 0;
|
|
});
|
|
},
|
|
child: Container(
|
|
width: 166,
|
|
height: 45,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: Color(pageIndex == 0 ? 0xFF0C0C0C : 0xFF17181A),
|
|
border: Border.all(color: Color(pageIndex == 0 ? 0xFF9C9C9C : 0xFF17181A), width: 1),
|
|
borderRadius: BorderRadius.all(Radius.circular(4))),
|
|
child: ShaderMask(
|
|
shaderCallback: (Rect bounds) {
|
|
return LinearGradient(
|
|
colors: pageIndex == 0
|
|
? [
|
|
Color(0xFF22F1F5),
|
|
Color(0xFF22F1F5),
|
|
Color(0xFF7A6EFA),
|
|
Color(0xFF7A6EFA),
|
|
]
|
|
: [
|
|
Color(0xFF909090),
|
|
Color(0xFF909090),
|
|
],
|
|
).createShader(bounds);
|
|
},
|
|
blendMode: BlendMode.srcATop,
|
|
child: Text(
|
|
'推荐',
|
|
style: TextStyle(fontSize: 14),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
setState(() {
|
|
pageIndex = 1;
|
|
});
|
|
},
|
|
child: Container(
|
|
width: 166,
|
|
height: 45,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: Color(pageIndex == 1 ? 0xFF0C0C0C : 0xFF17181A),
|
|
border: Border.all(color: Color(pageIndex == 1 ? 0xFF9C9C9C : 0xFF17181A), width: 1),
|
|
borderRadius: BorderRadius.all(Radius.circular(4))),
|
|
child: ShaderMask(
|
|
shaderCallback: (Rect bounds) {
|
|
return LinearGradient(
|
|
colors: pageIndex == 1
|
|
? [
|
|
Color(0xFF22F1F5),
|
|
Color(0xFF22F1F5),
|
|
Color(0xFF7A6EFA),
|
|
Color(0xFF7A6EFA),
|
|
]
|
|
: [
|
|
Color(0xFF909090),
|
|
Color(0xFF909090),
|
|
],
|
|
).createShader(bounds);
|
|
},
|
|
blendMode: BlendMode.srcATop,
|
|
child: Text(
|
|
'游戏排行',
|
|
style: TextStyle(fontSize: 14),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
Container(
|
|
child: pageIndex == 0
|
|
//推荐
|
|
? Column(
|
|
children: List.generate(homeInfoList.length, (index) => HomeRecommendPage(UniqueKey(), homeInfoBean: homeInfoList[index])),
|
|
)
|
|
//游戏排行
|
|
: HomeRankingPage(rankingList: rankingList),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
///顶部栏
|
|
Positioned(
|
|
top: MediaQuery.of(context).padding.top,
|
|
child: SizedBox(
|
|
width: size.width,
|
|
height: 40,
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
///搜索
|
|
Expanded(
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
Navigator.pushNamed(context, "/SearchPage");
|
|
},
|
|
child: Container(
|
|
margin: EdgeInsets.only(left: 14),
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(19.0),
|
|
child: BackdropFilter(
|
|
filter: ImageFilter.blur(
|
|
sigmaX: 5,
|
|
sigmaY: 5,
|
|
),
|
|
child: Container(
|
|
height: 36,
|
|
alignment: Alignment.centerLeft,
|
|
padding: EdgeInsets.only(left: 11),
|
|
decoration: const BoxDecoration(
|
|
color: Color(0x73FFFFFF),
|
|
borderRadius: BorderRadius.all(Radius.circular(19)),
|
|
),
|
|
child: Image(width: 16, height: 16, image: AssetImage('assets/images/ic_search.png')),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
///消息
|
|
GestureDetector(
|
|
onTap: () {
|
|
Navigator.pushNamed(context, "/MessageCenterPage").then((value) {
|
|
_viewModel.getUserMessageNotReadCount();
|
|
});
|
|
},
|
|
child: Container(
|
|
width: 36,
|
|
height: 36,
|
|
margin: EdgeInsets.only(right: 14, left: 25),
|
|
decoration: BoxDecoration(color: Color(0x73FFFFFF), borderRadius: BorderRadius.all(Radius.circular(19))),
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Image(
|
|
width: 17,
|
|
height: 14,
|
|
image: AssetImage('assets/images/ic_message.png'),
|
|
),
|
|
Positioned(
|
|
top: 8,
|
|
right: 7,
|
|
child: unreadNum > 0
|
|
? Container(
|
|
width: 4,
|
|
height: 4,
|
|
decoration: BoxDecoration(color: Colors.red, borderRadius: BorderRadius.all(Radius.circular(10))),
|
|
)
|
|
: Container())
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
_bannerItem() {
|
|
return bannerList.map((value) {
|
|
return Builder(builder: (BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: () {
|
|
_jumpToPage(value);
|
|
},
|
|
child: SizedBox(
|
|
height: 387,
|
|
child: CachedNetworkImage(
|
|
width: MediaQuery.of(context).size.width,
|
|
height: 387,
|
|
imageUrl: '${value.imageUrl}',
|
|
errorWidget: (context, url, error) => const Icon(Icons.error),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
}).toList();
|
|
}
|
|
|
|
///跳转页面
|
|
_jumpToPage(value) {
|
|
switch (value.resType) {
|
|
case 1: //游戏详情
|
|
break;
|
|
case 2: //app页面
|
|
switch (value.resId) {
|
|
case "shop": //商城
|
|
break;
|
|
case "Task": //任务中心
|
|
break;
|
|
}
|
|
break;
|
|
case 3: //内部H5
|
|
break;
|
|
case 4: //外部H5
|
|
break;
|
|
}
|
|
}
|
|
}
|