SteamCloudGame/lib/tools/me/game_history_page.dart
2024-11-23 15:25:11 +08:00

137 lines
3.7 KiB
Dart

import 'dart:async';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import '../../beans/game_history_bean.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;
}
setState(() {});
}
});
_viewModel.getGameHistory();
}
@override
void dispose() {
// TODO: implement dispose
subscription.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: const Color(0xFF17181A),
body: Column(
children: [
Container(
width: size.width,
height: 50,
margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
child: Stack(
alignment: Alignment.center,
children: [
Text(
"游玩历史",
style: TextStyle(fontSize: 16, color: Color(0xFFD6D6D7)),
),
Positioned(
left: 14,
child: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Image(
width: 19,
height: 26,
image: AssetImage('assets/images/btn_fanhui.png'),
),
),
)
],
),
),
Expanded(
child: Container(
margin: EdgeInsets.only(left: 14, right: 14),
child: ListView.builder(
padding: EdgeInsets.zero,
itemCount: dataList.length,
itemBuilder: (context, index) {
return _item(dataList[index]);
}),
)),
],
),
);
}
_item(GameHistoryBean data) {
return Container(
height: 99,
margin: EdgeInsets.only(top: 18),
decoration: BoxDecoration(color: Color(0xFF202530), borderRadius: BorderRadius.all(Radius.circular(11))),
child: Stack(
children: [
Positioned(
left: 16,
top: 16,
child: Row(
children: [
CachedNetworkImage(
width: 50,
height: 50,
imageUrl: '${data.gameIconImage}',
errorWidget: (context, url, error) => const Icon(Icons.error),
),
Container(
margin: EdgeInsets.only(left: 10),
child: Text(
"${data.gameName}",
style: TextStyle(fontSize: 14, color: Color(0xFFD6D6D7)),
),
),
],
)),
Positioned(
left: 16,
top: 80,
child: Text(
"${data.playtime}",
style: TextStyle(fontSize: 9, color: Color(0xFF9D9D9D)),
))
],
),
);
}
}