Competitions.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:redux/redux.dart';
  4. import 'package:flutter_redux/flutter_redux.dart';
  5. import 'package:url_launcher/url_launcher.dart';
  6. import 'package:wanna_battle/styles/colors.dart';
  7. import '../redux/AppState.dart';
  8. import '../model/UserInfo.dart';
  9. import 'package:cached_network_image/cached_network_image.dart';
  10. import '../net/Result.dart';
  11. import '../net/HttpManager.dart';
  12. import '../model/CompetitionInfo.dart';
  13. import '../widget/Competition.dart';
  14. import '../widget/CheckinDialog.dart';
  15. import './BonusDialog.dart';
  16. import 'AppNotice.dart';
  17. class Competitions extends StatefulWidget {
  18. Competitions({Key key}) : super(key: key);
  19. @override
  20. State<StatefulWidget> createState() => _CompetitionState();
  21. }
  22. class _CompetitionState extends State<Competitions> {
  23. List<CompetitionInfo> competitionInfoList = [];
  24. bool showDownload = false;
  25. @override
  26. void initState() {
  27. super.initState();
  28. setState(() {
  29. competitionInfoList = PageStorage.of(context).readState(context, identifier: ValueKey('page1')) ?? [];
  30. });
  31. Future.delayed(Duration.zero, () async {
  32. _getCompetitions();
  33. const url = 'pubgmhd1106467070://';
  34. final bool gameInstalled = await canLaunch(url);
  35. if (!gameInstalled) {
  36. setState(() {
  37. showDownload = true;
  38. });
  39. }
  40. });
  41. }
  42. @override
  43. Widget build(BuildContext context) {
  44. return StoreConnector<AppState, UserInfo>(
  45. converter: (Store store) => store.state.userInfo,
  46. builder: (context, userInfo) => Material(
  47. child: CupertinoPageScaffold(
  48. backgroundColor: Color(0xFF0E1D32),
  49. child: SizedBox(
  50. width: double.infinity,
  51. child: Column(
  52. children: <Widget>[
  53. Container(
  54. color: Color(0xff293354),
  55. child: SafeArea(
  56. child: SizedBox(
  57. width: double.infinity,
  58. height: 60,
  59. child: Container(
  60. child: Row(
  61. mainAxisAlignment: MainAxisAlignment.center,
  62. children: <Widget>[
  63. Container(
  64. child: ClipOval(
  65. child: Builder(
  66. builder: (context) {
  67. return Material(
  68. child: InkWell(
  69. child: CachedNetworkImage(
  70. imageUrl: userInfo.icon,
  71. width: 42,
  72. height: 42,
  73. ),
  74. onTap: () {
  75. Scaffold.of(context).openDrawer();
  76. },
  77. ),
  78. );
  79. },
  80. ),
  81. ),
  82. margin: EdgeInsets.only(left: 15),
  83. ),
  84. Expanded(
  85. child: Container(
  86. height: 42,
  87. margin: EdgeInsets.only(left: 8),
  88. child: Column(
  89. crossAxisAlignment: CrossAxisAlignment.start,
  90. mainAxisAlignment: MainAxisAlignment.center,
  91. children: <Widget>[
  92. Text(
  93. userInfo.nickname,
  94. style: TextStyle(
  95. fontSize: 16,
  96. color: Colors.white,
  97. fontWeight: FontWeight.bold,
  98. ),
  99. ),
  100. // Row(
  101. // children: <Widget>[
  102. // Text(
  103. // '最强王者',
  104. // style: TextStyle(
  105. // color: Color(0xFFFC9A3B),
  106. // fontSize: 13,
  107. // fontWeight: FontWeight.bold,
  108. // ),
  109. // ),
  110. // Container(
  111. // margin: EdgeInsets.only(left: 0),
  112. // child: Image.asset('images/icon_jinbi.png'),
  113. // ),
  114. // Container(
  115. // margin: EdgeInsets.only(left: 2),
  116. // child: Text(
  117. // userInfo.moneyCoin
  118. // .floor()
  119. // .toString()
  120. // .replaceAllMapped(RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'), (Match m) => '${m[1]},'),
  121. // style: TextStyle(
  122. // color: Colors.white,
  123. // fontWeight: FontWeight.bold,
  124. // fontSize: 16,
  125. // ),
  126. // ),
  127. // )
  128. // ],
  129. // )
  130. ],
  131. ),
  132. ),
  133. ),
  134. Container(
  135. margin: EdgeInsets.fromLTRB(10, 0, 15, 0),
  136. child: GestureDetector(
  137. child: Image.asset('images/icon_jiangli.png'),
  138. onTap: () async {
  139. showBonusDialog(context, competitionInfoList);
  140. // getAppNotice(context);
  141. },
  142. ),
  143. ),
  144. ],
  145. ),
  146. ),
  147. ),
  148. ),
  149. ),
  150. Expanded(
  151. child: RefreshIndicator(
  152. child: Container(
  153. width: double.infinity,
  154. child: ListView(
  155. padding: EdgeInsets.fromLTRB(0, 7, 0, 7),
  156. children: buidChildren(),
  157. ),
  158. ),
  159. onRefresh: () {
  160. return _getCompetitions();
  161. },
  162. ),
  163. )
  164. ],
  165. ),
  166. ),
  167. ),
  168. ));
  169. }
  170. List<Widget> buidChildren() {
  171. List<Widget> list = [];
  172. if (showDownload) {
  173. list.add(Container(
  174. height: 60,
  175. padding: EdgeInsets.only(left: 15, right: 15),
  176. margin: EdgeInsets.only(top: 15),
  177. child: Row(
  178. children: <Widget>[
  179. Image.asset(
  180. 'images/download.png',
  181. width: 60,
  182. height: 60,
  183. ),
  184. Expanded(
  185. child: Column(
  186. children: <Widget>[
  187. Expanded(
  188. child: Text(
  189. '如果您还没安装《和平精英》请点击安装!',
  190. style: TextStyle(color: Colors.white, fontSize: 14),
  191. ),
  192. ),
  193. Row(
  194. mainAxisAlignment: MainAxisAlignment.end,
  195. children: <Widget>[
  196. SizedBox(
  197. width: 64,
  198. height: 24,
  199. child: OutlineButton(
  200. borderSide: BorderSide(color: Color(0xff4F5C87)),
  201. splashColor: Color(0xff4F5C87).withAlpha(128),
  202. color: Color(0xff4F5C87),
  203. onPressed: () {
  204. setState(() {
  205. showDownload = false;
  206. });
  207. },
  208. child: Text(
  209. '取消',
  210. style: TextStyle(
  211. color: Color(0xff4F5C87),
  212. fontSize: 12,
  213. ),
  214. ),
  215. ),
  216. ),
  217. Container(
  218. margin: EdgeInsets.only(left: 15),
  219. child: SizedBox(
  220. width: 64,
  221. height: 24,
  222. child: OutlineButton(
  223. borderSide: BorderSide(color: PRIMARY_COLOR),
  224. onPressed: () async {
  225. const url = 'https://gp.qq.com/cp/a20190617versionm/m_version.html?ADTAG=media.buy.baidubrand.title';
  226. if (await canLaunch(url)) {
  227. await launch(url);
  228. }
  229. setState(() {
  230. showDownload = false;
  231. });
  232. },
  233. child: Text(
  234. '下载',
  235. style: TextStyle(
  236. color: PRIMARY_COLOR,
  237. fontSize: 12,
  238. ),
  239. ),
  240. ),
  241. ),
  242. )
  243. ],
  244. )
  245. ],
  246. ),
  247. )
  248. ],
  249. ),
  250. ));
  251. }
  252. list.add(Container(
  253. height: 56,
  254. padding: EdgeInsets.only(left: 15, right: 15),
  255. child: Row(
  256. children: <Widget>[
  257. Expanded(
  258. child: Container(height: 2, color: Color(0xFF293354)),
  259. ),
  260. Container(
  261. margin: EdgeInsets.only(left: 10, right: 10),
  262. child: Text(
  263. '赛事列表',
  264. style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold),
  265. ),
  266. ),
  267. Expanded(
  268. child: Container(height: 2, color: Color(0xFF293354)),
  269. )
  270. ],
  271. ),
  272. ));
  273. for (CompetitionInfo competitionInfo in competitionInfoList) {
  274. list.add(Competition(competitionInfo));
  275. }
  276. return list;
  277. }
  278. Future<void> _getCompetitions() async {
  279. Result res = await HttpManager.get('competition/getCompetitionList');
  280. if (res.success) {
  281. List<CompetitionInfo> list = [];
  282. for (var item in res.data) {
  283. list.add(CompetitionInfo.fromJson(item));
  284. }
  285. setState(() {
  286. competitionInfoList = list;
  287. PageStorage.of(context).writeState(context, competitionInfoList, identifier: ValueKey('page1'));
  288. });
  289. }
  290. }
  291. }