Competitions.dart 9.3 KB

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