| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- 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<StatefulWidget> createState() => _CompetitionState();
- }
- class _CompetitionState extends State<Competitions> {
- List<CompetitionInfo> 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<AppState, UserInfo>(
- converter: (Store store) => store.state.userInfo,
- builder: (context, userInfo) => Material(
- child: CupertinoPageScaffold(
- backgroundColor: Color(0xFF0E1D32),
- child: SizedBox(
- width: double.infinity,
- child: Column(
- children: <Widget>[
- Container(
- color: Color(0xff293354),
- child: SafeArea(
- child: SizedBox(
- width: double.infinity,
- height: 60,
- child: Container(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- 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: <Widget>[
- Text(
- userInfo.nickname,
- style: TextStyle(
- fontSize: 16,
- color: Colors.white,
- fontWeight: FontWeight.bold,
- ),
- ),
- // Row(
- // children: <Widget>[
- // 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<Widget> buidChildren() {
- List<Widget> list = [];
- if (showDownload) {
- list.add(Container(
- height: 60,
- padding: EdgeInsets.only(left: 15, right: 15),
- margin: EdgeInsets.only(top: 15),
- child: Row(
- children: <Widget>[
- Image.asset(
- 'images/download.png',
- width: 60,
- height: 60,
- ),
- Expanded(
- child: Column(
- children: <Widget>[
- Expanded(
- child: Text(
- '如果您还没安装《和平精英》请点击安装!',
- style: TextStyle(color: Colors.white, fontSize: 14),
- ),
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: <Widget>[
- 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: <Widget>[
- 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<void> _getCompetitions() async {
- Result res = await HttpManager.get('competition/getCompetitionList');
- if (res.success) {
- List<CompetitionInfo> list = [];
- for (var item in res.data) {
- list.add(CompetitionInfo.fromJson(item));
- }
- setState(() {
- competitionInfoList = list;
- PageStorage.of(context).writeState(context, competitionInfoList, identifier: ValueKey('page1'));
- });
- }
- }
- }
|