import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:redux/redux.dart'; import 'package:flutter_redux/flutter_redux.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:wanna_battle/styles/colors.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'; import 'AppNotice.dart'; class Competitions extends StatefulWidget { Competitions({Key key}) : super(key: key); @override State createState() => _CompetitionState(); } class _CompetitionState extends State { List competitionInfoList = []; bool showDownload = false; @override void initState() { super.initState(); setState(() { competitionInfoList = PageStorage.of(context).readState(context, identifier: ValueKey('page1')) ?? []; }); Future.delayed(Duration.zero, () async { _getCompetitions(); const url = 'pubgmhd1106467070://'; final bool gameInstalled = await canLaunch(url); if (!gameInstalled) { setState(() { showDownload = true; }); } }); } @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, mainAxisAlignment: MainAxisAlignment.center, children: [ Text( userInfo.nickname, 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: GestureDetector( child: Image.asset('images/icon_jiangli.png'), onTap: () async { showBonusDialog(context, competitionInfoList); // getAppNotice(context); }, ), ), ], ), ), ), ), ), 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 = []; if (showDownload) { list.add(Container( height: 60, padding: EdgeInsets.only(left: 15, right: 15), margin: EdgeInsets.only(top: 15), child: Row( children: [ Image.asset( 'images/download.png', width: 60, height: 60, ), Expanded( child: Column( children: [ Expanded( child: Text( '如果您还没安装《和平精英》请点击安装!', style: TextStyle(color: Colors.white, fontSize: 14), ), ), Row( mainAxisAlignment: MainAxisAlignment.end, children: [ SizedBox( width: 64, height: 24, child: OutlineButton( borderSide: BorderSide(color: Color(0xff4F5C87)), splashColor: Color(0xff4F5C87).withAlpha(128), color: Color(0xff4F5C87), onPressed: () { setState(() { showDownload = false; }); }, child: Text( '取消', style: TextStyle( color: Color(0xff4F5C87), fontSize: 12, ), ), ), ), Container( margin: EdgeInsets.only(left: 15), child: SizedBox( width: 64, height: 24, child: OutlineButton( borderSide: BorderSide(color: PRIMARY_COLOR), onPressed: () async { const url = 'https://gp.qq.com/cp/a20190617versionm/m_version.html?ADTAG=media.buy.baidubrand.title'; if (await canLaunch(url)) { await launch(url); } setState(() { showDownload = false; }); }, child: Text( '下载', style: TextStyle( color: PRIMARY_COLOR, fontSize: 12, ), ), ), ), ) ], ) ], ), ) ], ), )); } 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')); }); } } }