import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:redux/redux.dart'; import 'package:flutter_redux/flutter_redux.dart'; import '../redux/AppState.dart'; import '../model/UserInfo.dart'; import 'package:cached_network_image/cached_network_image.dart'; import '../net/Result.dart'; import '../net/HttpManager.dart'; import '../model/CompetitionInfo.dart'; import '../widget/Competition.dart'; import '../widget/CheckinDialog.dart'; import './BonusDialog.dart'; class Competitions extends StatefulWidget { Competitions({Key key}) : super(key: key); @override State createState() => _CompetitionState(); } class _CompetitionState extends State { List competitionInfoList = []; @override void initState() { super.initState(); setState(() { competitionInfoList = PageStorage.of(context) .readState(context, identifier: ValueKey('page1')) ?? []; }); Future.delayed(Duration.zero, () { _getCompetitions(); }); } @override Widget build(BuildContext context) { return StoreConnector( converter: (Store store) => store.state.userInfo, builder: (context, userInfo) => Material( child: CupertinoPageScaffold( backgroundColor: Color(0xFF0E1D32), child: SizedBox( width: double.infinity, child: Column( children: [ Container( color: Color(0xff293354), child: SafeArea( child: SizedBox( width: double.infinity, height: 60, child: Container( child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( child: ClipOval( child: Builder( builder: (context) { return Material( child: InkWell( child: CachedNetworkImage( imageUrl: userInfo.icon, width: 42, height: 42, ), onTap: () { Scaffold.of(context) .openDrawer(); }, ), ); }, ), ), margin: EdgeInsets.only(left: 15), ), Expanded( child: Container( height: 42, margin: EdgeInsets.only(left: 8), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( userInfo.username, style: TextStyle( fontSize: 16, color: Colors.white, fontWeight: FontWeight.bold, ), ), Row( children: [ // Text( // '最强王者', // style: TextStyle( // color: Color(0xFFFC9A3B), // fontSize: 13, // fontWeight: FontWeight.bold, // ), // ), Container( margin: EdgeInsets.only(left: 0), child: Image.asset( 'images/icon_jinbi.png'), ), Container( margin: EdgeInsets.only(left: 2), child: Text( userInfo.moneyCoin .floor() .toString() .replaceAllMapped( RegExp( r'(\d{1,3})(?=(\d{3})+(?!\d))'), (Match m) => '${m[1]},'), style: TextStyle( color: Colors.white, fontWeight: FontWeight.bold, fontSize: 16, ), ), ) ], ) ], ), ), ), Container( margin: EdgeInsets.fromLTRB(10, 0, 15, 0), child: InkWell( child: Container( width: 62, height: 32, color: Color(0xFFE56B45), child: Row( children: [ Container( margin: EdgeInsets.only(left: 6), child: Image.asset( 'images/icon_jiangpin.png', width: 20, height: 20, ), ), Container( margin: EdgeInsets.only(left: 2), child: Text( '奖品', style: TextStyle( fontSize: 14, color: Colors.white, ), ), ) ], ), ), onTap: () async { showBonusDialog( context, competitionInfoList); }, ), ), ], ), ), ), ), ), Expanded( child: RefreshIndicator( child: Container( width: double.infinity, child: ListView( padding: EdgeInsets.fromLTRB(0, 7, 0, 7), children: buidChildren(), ), ), onRefresh: () { return _getCompetitions(); }, ), ) ], ), ), ), )); } List buidChildren() { List list = []; list.add(Container( height: 56, padding: EdgeInsets.only(left: 15, right: 15), child: Row( children: [ Expanded( child: Container(height: 2, color: Color(0xFF293354)), ), Container( margin: EdgeInsets.only(left: 10, right: 10), child: Text( '赛事列表', style: TextStyle( color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold), ), ), Expanded( child: Container(height: 2, color: Color(0xFF293354)), ) ], ), )); for (CompetitionInfo competitionInfo in competitionInfoList) { list.add(Competition(competitionInfo)); } return list; } Future _getCompetitions() async { Result res = await HttpManager.get('competition/getCompetitionList'); if (res.success) { List list = []; for (var item in res.data) { list.add(CompetitionInfo.fromJson(item)); } setState(() { competitionInfoList = list; PageStorage.of(context).writeState(context, competitionInfoList, identifier: ValueKey('page1')); }); } } }