Competitions.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 '../redux/AppState.dart';
  6. import '../model/UserInfo.dart';
  7. import 'package:cached_network_image/cached_network_image.dart';
  8. import '../net/Result.dart';
  9. import '../net/HttpManager.dart';
  10. import '../model/CompetitionInfo.dart';
  11. import '../widget/Competition.dart';
  12. import '../widget/CheckinDialog.dart';
  13. import './BonusDialog.dart';
  14. class Competitions extends StatefulWidget {
  15. Competitions({Key key}) : super(key: key);
  16. @override
  17. State<StatefulWidget> createState() => _CompetitionState();
  18. }
  19. class _CompetitionState extends State<Competitions> {
  20. List<CompetitionInfo> competitionInfoList = [];
  21. @override
  22. void initState() {
  23. super.initState();
  24. setState(() {
  25. competitionInfoList = PageStorage.of(context)
  26. .readState(context, identifier: ValueKey('page1')) ??
  27. [];
  28. });
  29. Future.delayed(Duration.zero, () {
  30. _getCompetitions();
  31. });
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. return StoreConnector<AppState, UserInfo>(
  36. converter: (Store store) => store.state.userInfo,
  37. builder: (context, userInfo) => Material(
  38. child: CupertinoPageScaffold(
  39. backgroundColor: Color(0xFF0E1D32),
  40. child: SizedBox(
  41. width: double.infinity,
  42. child: Column(
  43. children: <Widget>[
  44. Container(
  45. color: Color(0xff293354),
  46. child: SafeArea(
  47. child: SizedBox(
  48. width: double.infinity,
  49. height: 60,
  50. child: Container(
  51. child: Row(
  52. mainAxisAlignment: MainAxisAlignment.center,
  53. children: <Widget>[
  54. Container(
  55. child: ClipOval(
  56. child: Builder(
  57. builder: (context) {
  58. return Material(
  59. child: InkWell(
  60. child: CachedNetworkImage(
  61. imageUrl: userInfo.icon,
  62. width: 42,
  63. height: 42,
  64. ),
  65. onTap: () {
  66. Scaffold.of(context)
  67. .openDrawer();
  68. },
  69. ),
  70. );
  71. },
  72. ),
  73. ),
  74. margin: EdgeInsets.only(left: 15),
  75. ),
  76. Expanded(
  77. child: Container(
  78. height: 42,
  79. margin: EdgeInsets.only(left: 8),
  80. child: Column(
  81. crossAxisAlignment:
  82. CrossAxisAlignment.start,
  83. children: <Widget>[
  84. Text(
  85. userInfo.username,
  86. style: TextStyle(
  87. fontSize: 16,
  88. color: Colors.white,
  89. fontWeight: FontWeight.bold,
  90. ),
  91. ),
  92. Row(
  93. children: <Widget>[
  94. // Text(
  95. // '最强王者',
  96. // style: TextStyle(
  97. // color: Color(0xFFFC9A3B),
  98. // fontSize: 13,
  99. // fontWeight: FontWeight.bold,
  100. // ),
  101. // ),
  102. Container(
  103. margin:
  104. EdgeInsets.only(left: 0),
  105. child: Image.asset(
  106. 'images/icon_jinbi.png'),
  107. ),
  108. Container(
  109. margin:
  110. EdgeInsets.only(left: 2),
  111. child: Text(
  112. userInfo.moneyCoin
  113. .floor()
  114. .toString()
  115. .replaceAllMapped(
  116. RegExp(
  117. r'(\d{1,3})(?=(\d{3})+(?!\d))'),
  118. (Match m) =>
  119. '${m[1]},'),
  120. style: TextStyle(
  121. color: Colors.white,
  122. fontWeight: FontWeight.bold,
  123. fontSize: 16,
  124. ),
  125. ),
  126. )
  127. ],
  128. )
  129. ],
  130. ),
  131. ),
  132. ),
  133. Container(
  134. margin: EdgeInsets.fromLTRB(10, 0, 15, 0),
  135. child: InkWell(
  136. child: Container(
  137. width: 62,
  138. height: 32,
  139. color: Color(0xFFE56B45),
  140. child: Row(
  141. children: <Widget>[
  142. Container(
  143. margin: EdgeInsets.only(left: 6),
  144. child: Image.asset(
  145. 'images/icon_jiangpin.png',
  146. width: 20,
  147. height: 20,
  148. ),
  149. ),
  150. Container(
  151. margin: EdgeInsets.only(left: 2),
  152. child: Text(
  153. '奖品',
  154. style: TextStyle(
  155. fontSize: 14,
  156. color: Colors.white,
  157. ),
  158. ),
  159. )
  160. ],
  161. ),
  162. ),
  163. onTap: () async {
  164. showBonusDialog(
  165. context, competitionInfoList);
  166. },
  167. ),
  168. ),
  169. ],
  170. ),
  171. ),
  172. ),
  173. ),
  174. ),
  175. Expanded(
  176. child: RefreshIndicator(
  177. child: Container(
  178. width: double.infinity,
  179. child: ListView(
  180. padding: EdgeInsets.fromLTRB(0, 7, 0, 7),
  181. children: buidChildren(),
  182. ),
  183. ),
  184. onRefresh: () {
  185. return _getCompetitions();
  186. },
  187. ),
  188. )
  189. ],
  190. ),
  191. ),
  192. ),
  193. ));
  194. }
  195. List<Widget> buidChildren() {
  196. List<Widget> list = [];
  197. list.add(Container(
  198. height: 56,
  199. padding: EdgeInsets.only(left: 15, right: 15),
  200. child: Row(
  201. children: <Widget>[
  202. Expanded(
  203. child: Container(height: 2, color: Color(0xFF293354)),
  204. ),
  205. Container(
  206. margin: EdgeInsets.only(left: 10, right: 10),
  207. child: Text(
  208. '赛事列表',
  209. style: TextStyle(
  210. color: Colors.white,
  211. fontSize: 16,
  212. fontWeight: FontWeight.bold),
  213. ),
  214. ),
  215. Expanded(
  216. child: Container(height: 2, color: Color(0xFF293354)),
  217. )
  218. ],
  219. ),
  220. ));
  221. for (CompetitionInfo competitionInfo in competitionInfoList) {
  222. list.add(Competition(competitionInfo));
  223. }
  224. return list;
  225. }
  226. Future<void> _getCompetitions() async {
  227. Result res = await HttpManager.get('competition/getCompetitionList');
  228. if (res.success) {
  229. List<CompetitionInfo> list = [];
  230. for (var item in res.data) {
  231. list.add(CompetitionInfo.fromJson(item));
  232. }
  233. setState(() {
  234. competitionInfoList = list;
  235. PageStorage.of(context).writeState(context, competitionInfoList,
  236. identifier: ValueKey('page1'));
  237. });
  238. }
  239. }
  240. }