479 lines
19 KiB
Dart
479 lines
19 KiB
Dart
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../beans/home_ranking_bean.dart';
|
|
import '../../common/EventBusUtil.dart';
|
|
import '../game/game_info_page.dart';
|
|
|
|
class HomeRankingPage extends StatefulWidget {
|
|
final List<HomeRankingBean> rankingList;
|
|
|
|
const HomeRankingPage({super.key, required this.rankingList});
|
|
|
|
@override
|
|
State<HomeRankingPage> createState() => _HomeRankingPageState();
|
|
}
|
|
|
|
class _HomeRankingPageState extends State<HomeRankingPage> {
|
|
List<HomeRankingBean> gameList = [];
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
gameList = widget.rankingList.sublist(3);
|
|
}
|
|
|
|
///开始游戏
|
|
_playGame(gameId) {
|
|
EventBusUtil.fire(StartGames(gameId));
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final size = MediaQuery.of(context).size;
|
|
final h250 = size.width / 1.44;
|
|
final l15 = size.width / 24;
|
|
final w99 = size.width / 3.63636363636;
|
|
final h160 = size.width / 2.25;
|
|
final h104 = size.width / 3.4615384615384;
|
|
final w20 = size.width / 18;
|
|
final w57 = size.width / 6.3157894736842;
|
|
final w75 = size.width / 4.8;
|
|
final h29 = size.width / 12.413793103448;
|
|
final c18 = size.width / 20;
|
|
final h181 = size.width / 1.988950276243;
|
|
final h126 = size.width / 2.8571428571428;
|
|
final t17 = size.width / 21.176470588235;
|
|
final s14 = size.width / 25.714285714285;
|
|
final s13 = size.width / 27.692307692307;
|
|
final l11 = size.width / 32.727272727272;
|
|
final s12 = size.width / 30;
|
|
final t8 = size.width / 45;
|
|
final t9 = size.width / 40;
|
|
|
|
return Column(
|
|
children: [
|
|
///游玩时长前三游戏
|
|
Container(
|
|
width: size.width,
|
|
height: h250,
|
|
margin: EdgeInsets.only(left: l15, right: l15),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
//导航打开新视图
|
|
builder: (context) => GameInfoPage(
|
|
gameId: "${widget.rankingList[1].gameId}",
|
|
),
|
|
));
|
|
},
|
|
child: SizedBox(
|
|
width: w99,
|
|
height: h160,
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Positioned(
|
|
bottom: 0,
|
|
child: Container(
|
|
width: w99,
|
|
height: h104,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(l11)),
|
|
gradient: const LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [
|
|
Color(0xFF39ADFE),
|
|
Color(0xFF0978FF),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Positioned(
|
|
top: 0,
|
|
child: Column(
|
|
children: [
|
|
ClipOval(
|
|
child: Container(
|
|
width: w20,
|
|
height: w20,
|
|
alignment: Alignment.center,
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [
|
|
Color(0xFFC3D2DE),
|
|
Color(0xFF949EC8),
|
|
],
|
|
),
|
|
),
|
|
child: Text(
|
|
"2",
|
|
style: TextStyle(fontSize: s12, color: Colors.white),
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: l11),
|
|
child: CachedNetworkImage(
|
|
width: w57,
|
|
height: w57,
|
|
imageUrl: '${widget.rankingList[1].gameIconImage}',
|
|
errorWidget: (context, url, error) => const Icon(Icons.error),
|
|
),
|
|
),
|
|
Container(
|
|
width: w75,
|
|
margin: EdgeInsets.only(top: t8),
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
"${widget.rankingList[1].gameName}",
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(fontSize: s14, color: Colors.white),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
_playGame(widget.rankingList[1].gameId);
|
|
},
|
|
child: Container(
|
|
width: w75,
|
|
height: h29,
|
|
alignment: Alignment.center,
|
|
margin: EdgeInsets.only(top: t9),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.all(Radius.circular(c18)),
|
|
),
|
|
child: Text(
|
|
'打开',
|
|
style: TextStyle(color: Color(0xFF1282FF), fontSize: s13),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
))
|
|
],
|
|
),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => GameInfoPage(
|
|
gameId: "${widget.rankingList[0].gameId}",
|
|
),
|
|
));
|
|
},
|
|
child: SizedBox(
|
|
width: w99,
|
|
height: h181,
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Positioned(
|
|
bottom: 0,
|
|
child: Container(
|
|
width: w99,
|
|
height: h126,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(l11)),
|
|
gradient: const LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [
|
|
Color(0xFFFE924B),
|
|
Color(0xFFF65A2E),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Positioned(
|
|
top: 0,
|
|
child: Column(
|
|
children: [
|
|
ClipOval(
|
|
child: Container(
|
|
width: w20,
|
|
height: w20,
|
|
alignment: Alignment.center,
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [
|
|
Color(0xFFFFE660),
|
|
Color(0xFFFD9E2A),
|
|
],
|
|
),
|
|
),
|
|
child: Text(
|
|
"1",
|
|
style: TextStyle(fontSize: s12, color: Colors.white),
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: l11),
|
|
child: CachedNetworkImage(
|
|
width: w57,
|
|
height: w57,
|
|
imageUrl: '${widget.rankingList[0].gameIconImage}',
|
|
errorWidget: (context, url, error) => const Icon(Icons.error),
|
|
),
|
|
),
|
|
Container(
|
|
width: w75,
|
|
margin: EdgeInsets.only(top: t17),
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
"${widget.rankingList[0].gameName}",
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(fontSize: s14, color: Colors.white),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
_playGame(widget.rankingList[0].gameId);
|
|
},
|
|
child: Container(
|
|
width: w75,
|
|
height: h29,
|
|
alignment: Alignment.center,
|
|
margin: EdgeInsets.only(top: c18),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.all(Radius.circular(c18)),
|
|
),
|
|
child: Text(
|
|
'打开',
|
|
style: TextStyle(color: Color(0xFFF86534), fontSize: s13),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
))
|
|
],
|
|
),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
//导航打开新视图
|
|
builder: (context) => GameInfoPage(
|
|
gameId: "${widget.rankingList[2].gameId}",
|
|
),
|
|
));
|
|
},
|
|
child: SizedBox(
|
|
width: w99,
|
|
height: h160,
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Positioned(
|
|
bottom: 0,
|
|
child: Container(
|
|
width: w99,
|
|
height: h104,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(l11)),
|
|
gradient: const LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [
|
|
Color(0xFFEE5361),
|
|
Color(0xFFF52E30),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Positioned(
|
|
top: 0,
|
|
child: Column(
|
|
children: [
|
|
ClipOval(
|
|
child: Container(
|
|
width: w20,
|
|
height: w20,
|
|
alignment: Alignment.center,
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [
|
|
Color(0xFFEDC1A5),
|
|
Color(0xFFE17C38),
|
|
],
|
|
),
|
|
),
|
|
child: Text(
|
|
"3",
|
|
style: TextStyle(fontSize: s12, color: Colors.white),
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: l11),
|
|
child: CachedNetworkImage(
|
|
width: w57,
|
|
height: w57,
|
|
imageUrl: '${widget.rankingList[2].gameIconImage}',
|
|
errorWidget: (context, url, error) => const Icon(Icons.error),
|
|
),
|
|
),
|
|
Container(
|
|
width: w75,
|
|
margin: EdgeInsets.only(top: t8),
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
"${widget.rankingList[2].gameName}",
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(fontSize: s14, color: Colors.white),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
_playGame(widget.rankingList[2].gameId);
|
|
},
|
|
child: Container(
|
|
width: w75,
|
|
height: h29,
|
|
alignment: Alignment.center,
|
|
margin: EdgeInsets.only(top: t9),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.all(Radius.circular(c18)),
|
|
),
|
|
child: Text(
|
|
'打开',
|
|
style: TextStyle(color: Color(0xFFF3353A), fontSize: s13),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
))
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
///游玩历史列表
|
|
Container(
|
|
margin: EdgeInsets.only(left: l15, right: l15, bottom: w20),
|
|
child: ListView.builder(
|
|
padding: EdgeInsets.zero,
|
|
itemCount: gameList.length,
|
|
shrinkWrap: true,
|
|
physics: NeverScrollableScrollPhysics(),
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return _gameItem(index, gameList[index], context);
|
|
}),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
_gameItem(index, HomeRankingBean data, context) {
|
|
final size = MediaQuery.of(context).size;
|
|
final h60 = size.width / 6;
|
|
final t18 = size.width / 20;
|
|
final w25 = size.width / 14.4;
|
|
final w57 = size.width / 6.3157894736842;
|
|
final h32 = size.width / 11.25;
|
|
final w75 = size.width / 4.8;
|
|
final w130 = size.width / 2.7692307692307;
|
|
final s14 = size.width / 25.714285714285;
|
|
final s13 = size.width / 27.692307692307;
|
|
final l11 = size.width / 32.727272727272;
|
|
|
|
return GestureDetector(
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
//导航打开新视图
|
|
builder: (context) => GameInfoPage(
|
|
gameId: "${data.gameId}",
|
|
),
|
|
));
|
|
},
|
|
child: Container(
|
|
width: double.infinity,
|
|
height: h60,
|
|
margin: EdgeInsets.only(top: t18),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
width: w25,
|
|
height: w25,
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
"${index + 4}.",
|
|
style: TextStyle(fontSize: s14, color: Colors.white),
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(left: s13),
|
|
child: CachedNetworkImage(
|
|
width: w57,
|
|
height: w57,
|
|
imageUrl: '${data.gameIconImage}',
|
|
errorWidget: (context, url, error) => const Icon(Icons.error),
|
|
),
|
|
),
|
|
Container(
|
|
width: w130,
|
|
margin: EdgeInsets.only(left: l11),
|
|
child: Text(
|
|
"${data.gameName}",
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(fontSize: s14, color: Color(0xFFD6D6D7)),
|
|
),
|
|
),
|
|
Expanded(child: Container()),
|
|
GestureDetector(
|
|
onTap: () {
|
|
_playGame(data.gameId);
|
|
},
|
|
child: Container(
|
|
width: w75,
|
|
height: h32,
|
|
alignment: Alignment.center,
|
|
margin: EdgeInsets.only(left: s13),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFF074CE7),
|
|
borderRadius: BorderRadius.all(Radius.circular(t18)),
|
|
),
|
|
child: Text(
|
|
'打开',
|
|
style: TextStyle(color: Colors.white, fontSize: s13),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|