Competition.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. import 'package:intl/intl.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:cached_network_image/cached_network_image.dart';
  5. import 'package:gradient_text/gradient_text.dart';
  6. import 'package:wanna_battle/net/HttpManager.dart';
  7. import 'package:wanna_battle/styles/colors.dart';
  8. import '../pages/CompetitionRank.dart';
  9. import '../model/CompetitionInfo.dart';
  10. import '../pages/CompetitionRooms.dart';
  11. class Competition extends StatelessWidget {
  12. final CompetitionInfo competitionInfo;
  13. const Competition(this.competitionInfo, {Key key}) : super(key: key);
  14. @override
  15. Widget build(BuildContext context) {
  16. return GestureDetector(
  17. child: Container(
  18. margin: EdgeInsets.only(left: 15, right: 15, bottom: 15),
  19. child: AspectRatio(
  20. aspectRatio: 345 / 186,
  21. child: Stack(
  22. children: <Widget>[
  23. AspectRatio(
  24. aspectRatio: 345 / 186,
  25. child: CachedNetworkImage(
  26. imageUrl: competitionInfo.pic,
  27. fit: BoxFit.cover,
  28. ),
  29. ),
  30. AspectRatio(
  31. aspectRatio: 345 / 136,
  32. child: Container(
  33. decoration: BoxDecoration(
  34. gradient: LinearGradient(
  35. colors: [Color(0xff000000).withAlpha(128), Color(0xff000000).withAlpha(0)],
  36. begin: Alignment.topCenter,
  37. end: Alignment.bottomCenter,
  38. )),
  39. ),
  40. ),
  41. Align(
  42. alignment: Alignment.topLeft,
  43. child: Container(
  44. margin: EdgeInsets.only(top: 13, left: 15),
  45. child: Row(
  46. children: <Widget>[
  47. Text(
  48. competitionInfo.competitionName,
  49. style: TextStyle(
  50. color: Colors.white,
  51. fontSize: 18,
  52. fontWeight: FontWeight.bold,
  53. ),
  54. ),
  55. Container(
  56. height: 20,
  57. margin: EdgeInsets.only(left: 6),
  58. decoration: BoxDecoration(borderRadius: BorderRadius.circular(2), color: Colors.white),
  59. padding: EdgeInsets.only(left: 4, right: 4),
  60. child: GestureDetector(
  61. child: Center(
  62. child: Text(
  63. competitionInfo.participatingInfo?.rank != null ? ('第' + competitionInfo.participatingInfo.rank.toString() + '名') : '未上榜',
  64. style: TextStyle(
  65. color: Color(0xff19213B),
  66. fontSize: 12,
  67. ),
  68. ),
  69. ),
  70. onTap: () {
  71. Navigator.push(context, CupertinoPageRoute(builder: (context) => CompetitionRank(competitionId: competitionInfo.id)));
  72. },
  73. ),
  74. )
  75. ],
  76. ),
  77. ),
  78. ),
  79. Align(
  80. alignment: Alignment.topLeft,
  81. child: Container(
  82. margin: EdgeInsets.only(top: 44, left: 15),
  83. child: Text(
  84. readTimestamp(competitionInfo.startTime, 'yyyy.MM.dd') + '-' + readTimestamp(competitionInfo.endTime, 'yyyy.MM.dd'),
  85. style: TextStyle(
  86. color: Colors.white,
  87. fontSize: 12,
  88. ),
  89. ),
  90. ),
  91. ),
  92. Align(
  93. alignment: Alignment.topLeft,
  94. child: Container(
  95. decoration: BoxDecoration(border: Border.all(width: 1, color: Colors.white)),
  96. padding: EdgeInsets.only(left: 2, right: 2),
  97. margin: EdgeInsets.only(top: 82, left: 15),
  98. child: Text(
  99. '赛事奖励',
  100. style: TextStyle(
  101. color: Colors.white,
  102. fontSize: 12,
  103. ),
  104. ),
  105. ),
  106. ),
  107. Align(
  108. alignment: Alignment.bottomLeft,
  109. child: Container(
  110. margin: EdgeInsets.only(left: 15, bottom: 12),
  111. child: Row(
  112. children: competitionInfo.awardPic.split(',').map<Widget>((f) {
  113. return Container(
  114. width: 60,
  115. height: 60,
  116. margin: EdgeInsets.only(right: 5),
  117. decoration: BoxDecoration(
  118. borderRadius: BorderRadius.circular(2),
  119. color: Colors.white,
  120. ),
  121. child: CachedNetworkImage(
  122. imageUrl: f,
  123. fit: BoxFit.contain,
  124. ),
  125. );
  126. }).toList(),
  127. ),
  128. ),
  129. ),
  130. Align(
  131. alignment: Alignment.bottomRight,
  132. child: Container(
  133. margin: EdgeInsets.only(bottom: 12),
  134. child: Image.asset(competitionInfo.type == 2 ? 'images/icon_kaishi_vip.png' : 'images/icon_kaishi_putong.png'),
  135. ),
  136. )
  137. ],
  138. ),
  139. ),
  140. ),
  141. onTap: () {
  142. Navigator.push(context, CupertinoPageRoute(builder: (context) => CompetitionRooms(competitionInfo)));
  143. },
  144. );
  145. }
  146. }
  147. class CompetitionOld extends StatelessWidget {
  148. final CompetitionInfo competitionInfo;
  149. CompetitionOld(this.competitionInfo);
  150. @override
  151. Widget build(BuildContext context) {
  152. return GestureDetector(
  153. child: Container(
  154. color: Color(0xFF293354),
  155. height: 80,
  156. margin: EdgeInsets.fromLTRB(15, 7, 15, 7),
  157. child: Stack(
  158. overflow: Overflow.visible,
  159. children: <Widget>[
  160. Center(
  161. child: Row(
  162. children: <Widget>[
  163. Container(
  164. margin: EdgeInsets.only(left: 8),
  165. child: Image.asset(
  166. 'images/game.png',
  167. width: 64,
  168. height: 64,
  169. ),
  170. ),
  171. Expanded(
  172. child: Container(
  173. margin: EdgeInsets.only(left: 10),
  174. height: 64,
  175. child: Column(
  176. crossAxisAlignment: CrossAxisAlignment.start,
  177. children: <Widget>[
  178. Text(
  179. competitionInfo.competitionName,
  180. style: TextStyle(fontSize: 14, color: Colors.white),
  181. ),
  182. Expanded(
  183. child: GradientText(
  184. '¥' + competitionInfo.bonus.toString().replaceAllMapped(RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'), (Match m) => '${m[1]},'),
  185. gradient: LinearGradient(
  186. colors: [Color(0xFFFFC84B), Color(0xFFA26A23)],
  187. begin: Alignment.topCenter,
  188. end: Alignment.bottomCenter,
  189. ),
  190. style: TextStyle(fontSize: 20),
  191. textAlign: TextAlign.center),
  192. ),
  193. Text(
  194. '比赛时间' +
  195. DateFormat('yyyy.MM.dd').format(DateTime.fromMicrosecondsSinceEpoch(competitionInfo.startTime * 1000)) +
  196. '-' +
  197. DateFormat('yyyy.MM.dd').format(DateTime.fromMicrosecondsSinceEpoch(competitionInfo.endTime * 1000)),
  198. style: TextStyle(
  199. color: Color(0xFF9A9CA2),
  200. fontSize: 11,
  201. ),
  202. )
  203. ],
  204. ),
  205. ),
  206. )
  207. ],
  208. ),
  209. ),
  210. Positioned(
  211. right: 0,
  212. top: 0,
  213. bottom: 0,
  214. child: Image.asset('images/icon_jinru.png'),
  215. ),
  216. Positioned(
  217. right: 0,
  218. top: 0,
  219. bottom: 0,
  220. child: Container(
  221. width: 50,
  222. height: 80,
  223. child: Center(
  224. child: Text(
  225. '进入',
  226. style: TextStyle(fontSize: 15, color: Colors.white),
  227. ),
  228. ),
  229. ),
  230. ),
  231. Positioned(
  232. right: 60,
  233. top: -2,
  234. width: 52,
  235. height: 35,
  236. child: Container(
  237. transform: Matrix4.translationValues(0.0, -2.0, 0.0),
  238. child: Builder(
  239. builder: (context) {
  240. var src = 'images/icon_paimingno.png';
  241. if (competitionInfo.participatingInfo != null && competitionInfo.participatingInfo.rank > 0) {
  242. if (competitionInfo.participatingInfo.rank == 1) {
  243. src = 'images/icon_paiming01.png';
  244. } else if (competitionInfo.participatingInfo.rank == 2) {
  245. src = 'images/icon_paiming02.png';
  246. } else if (competitionInfo.participatingInfo.rank == 3) {
  247. src = 'images/icon_paiming03.png';
  248. } else {
  249. return Stack(
  250. children: <Widget>[
  251. Image.asset('images/icon_paiming0000.png'),
  252. Align(
  253. alignment: Alignment.topCenter,
  254. child: Container(
  255. margin: EdgeInsets.only(top: 10),
  256. child: Text(
  257. competitionInfo.participatingInfo.rank.toString(),
  258. style: TextStyle(
  259. fontSize: 16,
  260. fontWeight: FontWeight.bold,
  261. color: Colors.white,
  262. ),
  263. ),
  264. ),
  265. ),
  266. ],
  267. );
  268. }
  269. }
  270. return Image.asset(src);
  271. },
  272. ),
  273. ),
  274. ),
  275. Align(
  276. alignment: Alignment.topLeft,
  277. child: Opacity(
  278. opacity: competitionInfo.type == 2 ? 1.0 : 0,
  279. child: Image.asset(
  280. 'images/home_icon_vip.png',
  281. width: 28,
  282. height: 24,
  283. ),
  284. ),
  285. )
  286. ],
  287. ),
  288. ),
  289. onTap: () {
  290. Navigator.push(context, CupertinoPageRoute(builder: (context) => CompetitionRooms(competitionInfo)));
  291. },
  292. );
  293. }
  294. }