SteamCloudGame/lib/tools/me/game_history_page.dart
2024-12-01 18:09:13 +08:00

167 lines
4.8 KiB
Dart

import 'dart:async';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import '../../beans/game_history_bean.dart';
import '../../common/func.dart';
import '../game/game_info_page.dart';
import 'me_model.dart';
///游玩历史
class GameHistoryPage extends StatefulWidget {
const GameHistoryPage({super.key});
@override
State<GameHistoryPage> createState() => _GameHistoryPageState();
}
class _GameHistoryPageState extends State<GameHistoryPage> {
late StreamSubscription subscription;
final MeModel _viewModel = MeModel();
List<GameHistoryBean> dataList = [];
@override
void initState() {
// TODO: implement initState
super.initState();
subscription = _viewModel.streamController.stream.listen((event) {
String code = event['code'];
if (code.isNotEmpty) {
switch (code) {
case "getGameHistory":
dataList = event['data'];
break;
}
EasyLoading.dismiss();
setState(() {});
}
});
FunctionUtil.loading();
_viewModel.getGameHistory();
}
@override
void dispose() {
// TODO: implement dispose
subscription.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
final h50 = size.width / 7.2;
final s16 = size.width / 22.5;
final l14 = size.width / 25.71428571428571;
final w19 = size.width / 18.94736842105263;
final h26 = size.width / 13.84615384615385;
return Scaffold(
backgroundColor: const Color(0xFF17181A),
body: Column(
children: [
Container(
width: size.width,
height: h50,
margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
child: Stack(
alignment: Alignment.center,
children: [
Text(
"游玩历史",
style: TextStyle(fontSize: s16, color: Color(0xFFD6D6D7)),
),
Positioned(
left: l14,
child: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Image(
width: w19,
height: h26,
image: AssetImage('assets/images/btn_fanhui.png'),
),
),
)
],
),
),
Expanded(
child: Container(
margin: EdgeInsets.only(left: l14, right: l14),
child: ListView.builder(
padding: EdgeInsets.zero,
itemCount: dataList.length,
itemBuilder: (context, index) {
return _item(dataList[index], context);
}),
)),
],
),
);
}
_item(GameHistoryBean data, context) {
final size = MediaQuery.of(context).size;
final h99 = size.width / 3.636363636363636;
final t18 = size.width / 20;
final l16 = size.width / 22.5;
final w50 = size.width / 7.2;
final t80 = size.width / 4.5;
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
//导航打开新视图
builder: (context) => GameInfoPage(
gameId: "${data.gameId}",
),
));
},
child: Container(
height: h99,
margin: EdgeInsets.only(top: t18),
decoration: const BoxDecoration(color: Color(0xFF202530), borderRadius: BorderRadius.all(Radius.circular(11))),
child: Stack(
children: [
Positioned(
left: l16,
top: l16,
child: Row(
children: [
CachedNetworkImage(
width: w50,
height: w50,
imageUrl: '${data.gameIconImage}',
errorWidget: (context, url, error) => const Icon(Icons.error),
),
Container(
margin: const EdgeInsets.only(left: 10),
child: Text(
"${data.gameName}",
style: const TextStyle(fontSize: 14, color: Color(0xFFD6D6D7)),
),
),
],
)),
Positioned(
left: l16,
top: t80,
child: Text(
"${data.playtime}",
style: const TextStyle(fontSize: 9, color: Color(0xFF9D9D9D)),
))
],
),
),
);
}
}