import 'dart:async'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import '../../beans/search_bean.dart'; import 'me_model.dart'; class MyCollectPage extends StatefulWidget { const MyCollectPage({super.key}); @override State createState() => _MyCollectPageState(); } class _MyCollectPageState extends State { late StreamSubscription subscription; final MeModel _viewModel = MeModel(); List gameList = []; @override void initState() { // TODO: implement initState super.initState(); subscription = _viewModel.streamController.stream.listen((event) { String code = event['code']; if (code.isNotEmpty) { switch (code) { case "getGameCollect": gameList = event['data']; break; } setState(() {}); } }); _viewModel.getGameCollect(); } @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, top: 20), child: ListView.builder( padding: EdgeInsets.zero, itemCount: gameList.length, itemBuilder: (context, index) { return _gameItem(gameList[index]); }), )) ], ), ); } _gameItem(SearchBean data) { return Container( height: 76, padding: EdgeInsets.only(left: 11), decoration: BoxDecoration( color: Color(0xFF202530), borderRadius: BorderRadius.all(Radius.circular(11)), ), child: Row( children: [ CachedNetworkImage( width: 57, height: 57, imageUrl: '${data.gameIconImage}', errorWidget: (context, url, error) => const Icon(Icons.error), ), Container( margin: EdgeInsets.only(left: 11), child: Text( "${data.gameName}", style: TextStyle(fontSize: 14, color: Color(0xFFD6D6D7)), ), ), ], ), ); } }