RoomInfoDetail.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_redux/flutter_redux.dart';
  4. import 'package:wanna_battle/net/HttpManager.dart';
  5. import 'package:wanna_battle/redux/AppState.dart';
  6. import 'package:wanna_battle/styles/totast.dart';
  7. import '../Constants.dart';
  8. import '../styles/colors.dart';
  9. import '../widget/VideoWidget.dart';
  10. import '../model/HouseInfo.dart';
  11. import '../widget/Dialog.dart';
  12. import './CompetitionNotice.dart';
  13. import '../model/PlayerInfo.dart';
  14. class RoomInfoDetail extends StatefulWidget {
  15. RoomInfoDetail(this.houseInfo, this.playerInfo, {Key key, this.onStart, this.finishedPlayerNum = 0}) : super(key: key);
  16. final HouseInfo houseInfo;
  17. final PlayerInfo playerInfo;
  18. final VoidCallback onStart;
  19. final int finishedPlayerNum;
  20. @override
  21. State<StatefulWidget> createState() {
  22. return RoomInfoDetailState();
  23. }
  24. }
  25. class RoomInfoDetailState extends State<RoomInfoDetail> {
  26. String startCountDown;
  27. @override
  28. void initState() {
  29. super.initState();
  30. }
  31. @override
  32. Widget build(BuildContext context) {
  33. return Scaffold(
  34. body: Stack(
  35. children: <Widget>[
  36. ListView(
  37. children: <Widget>[
  38. widget.houseInfo != null ? VideoWidget(videoSrc: widget.houseInfo.video) : Container(),
  39. Container(
  40. height: 60,
  41. padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
  42. child: Row(
  43. children: <Widget>[
  44. Expanded(
  45. child: Text(
  46. widget.houseInfo.houseName,
  47. style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.white),
  48. ),
  49. ),
  50. Row(
  51. mainAxisAlignment: MainAxisAlignment.center,
  52. children: <Widget>[
  53. Image.asset(
  54. 'images/icon_renshu.png',
  55. width: 20,
  56. ),
  57. Text(
  58. (widget.houseInfo?.playerNumber ?? 0).toString() + '/' + (widget.houseInfo?.maxNumber ?? 0).toString(),
  59. style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: Color(0xFFB1B2C0)),
  60. ),
  61. ],
  62. )
  63. ],
  64. ),
  65. ),
  66. Container(
  67. height: 40,
  68. margin: EdgeInsets.fromLTRB(15, 0, 15, 0),
  69. color: Color(0x1A1990F8),
  70. child: Row(
  71. children: <Widget>[
  72. Expanded(
  73. flex: 1,
  74. child: CupertinoButton(
  75. padding: EdgeInsets.all(0),
  76. onPressed: () {
  77. if (widget.houseInfo.statusFlag == 0) {
  78. showCustomDialog(context, '比赛即将开始,确定离开房间?', isCancel: true, onsubmit: () async {
  79. Toast.show(context, '退出房间', -1, 'loading');
  80. await HttpManager.get('houseInfo/quitRoom', data: {'houseId': widget.houseInfo.id});
  81. Toast.hide();
  82. Navigator.of(context).pop();
  83. });
  84. } else {
  85. Navigator.of(context).pop();
  86. }
  87. },
  88. child: Text(
  89. '返回锦标赛',
  90. style: TextStyle(color: PRIMARY_COLOR, fontSize: 14, fontWeight: FontWeight.bold),
  91. ),
  92. ),
  93. ),
  94. Container(
  95. width: 1,
  96. height: 12,
  97. color: PRIMARY_COLOR,
  98. ),
  99. Expanded(
  100. flex: 1,
  101. child: CupertinoButton(
  102. padding: EdgeInsets.all(0),
  103. onPressed: () {
  104. showNotice(context);
  105. },
  106. child: Text(
  107. '竞赛须知',
  108. style: TextStyle(color: PRIMARY_COLOR, fontSize: 14, fontWeight: FontWeight.bold),
  109. ),
  110. ),
  111. ),
  112. ],
  113. ),
  114. ),
  115. // Container(
  116. // height: 40,
  117. // margin: EdgeInsets.fromLTRB(15, 10, 15, 0),
  118. // decoration: BoxDecoration(
  119. // color: Color(0x1AFFFF00),
  120. // border: Border.all(
  121. // width: 1,
  122. // color: Colors.yellow,
  123. // )),
  124. // child: Row(
  125. // mainAxisAlignment: MainAxisAlignment.spaceAround,
  126. // children: <Widget>[
  127. // Text('积分 加成+0%', style: TextStyle(color: Colors.yellow, fontSize: 12)),
  128. // Text('保底 0积分', style: TextStyle(color: Colors.yellow, fontSize: 12)),
  129. // ],
  130. // ),
  131. // ),
  132. tipText()
  133. ],
  134. ),
  135. Align(
  136. alignment: Alignment.bottomCenter,
  137. child: SafeArea(child: roomBtn()),
  138. )
  139. ],
  140. ),
  141. );
  142. }
  143. Widget tipText() {
  144. switch (widget.houseInfo.statusFlag) {
  145. case HouseStatus.WAIT:
  146. case HouseStatus.READY:
  147. return Container(
  148. margin: EdgeInsets.fromLTRB(15, 20, 15, 0),
  149. color: SUB_COLOR,
  150. padding: EdgeInsets.all(15),
  151. child: Text.rich(
  152. TextSpan(
  153. text: '待倒计时结束或人数满员时会自动开启比赛,请在此页面耐心等待其他人的加入,'
  154. '祝您取得好成绩'),
  155. style: TextStyle(color: Colors.white, fontSize: 13),
  156. ),
  157. );
  158. case HouseStatus.START:
  159. case HouseStatus.END:
  160. case HouseStatus.ANALYSIS:
  161. final time = widget.houseInfo.beginTime + 3600000 - DateTime.now().millisecondsSinceEpoch;
  162. return Container(
  163. margin: EdgeInsets.fromLTRB(15, 20, 15, 0),
  164. color: SUB_COLOR,
  165. padding: EdgeInsets.all(15),
  166. child: Text.rich(
  167. TextSpan(children: <TextSpan>[
  168. TextSpan(text: ((widget.playerInfo?.statusFlag ?? 0) == PlayerStatus.END) ? '你已完成本次比赛,当前完成人数' : '当前完成人数'),
  169. TextSpan(text: ' ${widget.finishedPlayerNum ?? 0} ', style: TextStyle(color: Colors.yellow, fontWeight: FontWeight.bold)),
  170. TextSpan(text: '比赛需要等待所有人完成后方可结算积分最迟结算时间还剩'),
  171. TextSpan(text: ' ${getCountDown(time)} ', style: TextStyle(color: Colors.yellow, fontWeight: FontWeight.bold)),
  172. TextSpan(text: ',你可以先去参加其他竞赛,稍后在“个人中心-我的战绩”中可以查看本次竞赛排名及积分详情'),
  173. ]),
  174. style: TextStyle(color: Colors.white, fontSize: 13),
  175. ),
  176. );
  177. break;
  178. case HouseStatus.SETTLEMENT:
  179. return Column(
  180. children: <Widget>[
  181. (widget.playerInfo != null && widget.playerInfo.ranking != null && widget.playerInfo.liveTime != null && widget.playerInfo.score != null)
  182. ? Container(
  183. margin: EdgeInsets.fromLTRB(15, 20, 15, 0),
  184. color: SUB_COLOR,
  185. padding: EdgeInsets.fromLTRB(15, 15, 0, 15),
  186. child: Column(
  187. mainAxisAlignment: MainAxisAlignment.center,
  188. crossAxisAlignment: CrossAxisAlignment.stretch,
  189. children: <Widget>[
  190. Text(
  191. '和平精英游戏结果',
  192. textAlign: TextAlign.left,
  193. style: TextStyle(color: Color(0x99FFFFFF)),
  194. ),
  195. Container(
  196. margin: EdgeInsets.only(top: 10),
  197. child: Row(
  198. children: <Widget>[
  199. Text(
  200. '名次',
  201. style: TextStyle(color: Colors.white, fontSize: 14),
  202. ),
  203. Expanded(
  204. child: Container(
  205. margin: EdgeInsets.only(left: 5),
  206. child: Text(
  207. widget.playerInfo?.ranking?.toString() ?? '',
  208. style: TextStyle(color: Colors.yellow, fontSize: 14, fontWeight: FontWeight.bold),
  209. ),
  210. ),
  211. ),
  212. Text(
  213. '时长',
  214. style: TextStyle(color: Colors.white, fontSize: 14),
  215. ),
  216. Expanded(
  217. child: Container(
  218. margin: EdgeInsets.only(left: 5),
  219. child: Text(
  220. widget.playerInfo?.liveTime != null ? (widget.playerInfo?.liveTime.toString() + '分钟') : '',
  221. style: TextStyle(color: Colors.yellow, fontSize: 14, fontWeight: FontWeight.bold),
  222. ),
  223. ),
  224. ),
  225. Text(
  226. '评分',
  227. style: TextStyle(color: Colors.white, fontSize: 14),
  228. ),
  229. Expanded(
  230. child: Container(
  231. margin: EdgeInsets.only(left: 5),
  232. child: Text(
  233. (widget.playerInfo?.score != null && widget.playerInfo.score > 0) ? widget.playerInfo.score.toString() : '',
  234. style: TextStyle(color: Colors.yellow, fontSize: 14, fontWeight: FontWeight.bold),
  235. ),
  236. ),
  237. ),
  238. ],
  239. ),
  240. ),
  241. ],
  242. ),
  243. )
  244. : Container(height: 10),
  245. Container(
  246. margin: EdgeInsets.fromLTRB(15, 5, 15, 20),
  247. color: SUB_COLOR,
  248. padding: EdgeInsets.all(15),
  249. child: Column(
  250. mainAxisAlignment: MainAxisAlignment.center,
  251. crossAxisAlignment: CrossAxisAlignment.stretch,
  252. children: <Widget>[
  253. Text(
  254. '比赛结果',
  255. textAlign: TextAlign.left,
  256. style: TextStyle(color: Color(0x99FFFFFF)),
  257. ),
  258. Container(
  259. margin: EdgeInsets.only(top: 10),
  260. child: Row(
  261. children: <Widget>[
  262. Expanded(
  263. child: Text(
  264. '参赛成员',
  265. style: TextStyle(color: Colors.white, fontSize: 14),
  266. textAlign: TextAlign.left,
  267. ),
  268. ),
  269. Text(
  270. widget.houseInfo?.playerNumber?.toString() ?? '',
  271. style: TextStyle(color: Colors.yellow, fontWeight: FontWeight.bold),
  272. )
  273. ],
  274. ),
  275. ),
  276. Container(
  277. margin: EdgeInsets.only(top: 10),
  278. child: Row(
  279. children: <Widget>[
  280. Expanded(
  281. child: Text(
  282. '我的排名',
  283. style: TextStyle(color: Colors.white, fontSize: 14),
  284. textAlign: TextAlign.left,
  285. ),
  286. ),
  287. Text(
  288. widget.playerInfo?.houseRank?.toString() ?? '',
  289. style: TextStyle(color: Colors.yellow, fontWeight: FontWeight.bold),
  290. )
  291. ],
  292. ),
  293. ),
  294. Container(
  295. margin: EdgeInsets.only(top: 10),
  296. child: Row(
  297. children: <Widget>[
  298. Expanded(
  299. child: Text(
  300. '本场比赛获得积分',
  301. style: TextStyle(color: Colors.white, fontSize: 14),
  302. textAlign: TextAlign.left,
  303. ),
  304. ),
  305. Container(
  306. margin: EdgeInsets.only(right: 3),
  307. width: 20,
  308. child: Image.asset('images/icon_jifen_da.png'),
  309. ),
  310. Text(
  311. widget.playerInfo?.points?.toString() ?? '0',
  312. style: TextStyle(color: Colors.yellow, fontWeight: FontWeight.bold),
  313. )
  314. ],
  315. ),
  316. ),
  317. (widget.playerInfo?.ranking ?? 99) == 1
  318. ? Container(
  319. margin: EdgeInsets.only(top: 5),
  320. child: Text(
  321. '吃鸡额外获得10积分',
  322. style: TextStyle(color: PRIMARY_COLOR, fontSize: 12),
  323. ),
  324. )
  325. : Container()
  326. ],
  327. ),
  328. )
  329. ],
  330. );
  331. }
  332. return Container();
  333. }
  334. Widget roomBtn() {
  335. switch (widget.houseInfo.statusFlag) {
  336. case HouseStatus.WAIT:
  337. case HouseStatus.READY:
  338. {
  339. if (widget.houseInfo.createUser == StoreProvider.of<AppState>(context).state.userInfo.id.toString()) {
  340. return startBtn();
  341. } else {
  342. return countDownBtn();
  343. }
  344. }
  345. break;
  346. case HouseStatus.START:
  347. case HouseStatus.END:
  348. {
  349. final time = widget.houseInfo.beginTime + 3600000 - DateTime.now().millisecondsSinceEpoch;
  350. return statusBtn(time > 0 ? ('最迟在' + getCountDown(time) + '后结算') : '等待结算');
  351. }
  352. break;
  353. case HouseStatus.SETTLEMENT:
  354. return statusBtn('已结束');
  355. break;
  356. case HouseStatus.ANALYSIS:
  357. return statusBtn('结算中...');
  358. default:
  359. return statusBtn('已结束', color: Color(0xFF4F5C87));
  360. }
  361. }
  362. Widget startBtn() {
  363. final time = widget.houseInfo.createTime + 600000 - DateTime.now().millisecondsSinceEpoch;
  364. return Container(
  365. margin: EdgeInsets.fromLTRB(15, 0, 15, 10),
  366. child: SizedBox(
  367. height: 48,
  368. width: double.infinity,
  369. child: FlatButton(
  370. color: PRIMARY_COLOR,
  371. child: Text.rich(
  372. TextSpan(children: [
  373. TextSpan(
  374. text: '开始比赛 ',
  375. style: TextStyle(fontSize: 16),
  376. ),
  377. TextSpan(
  378. text: '(${getCountDown(time)}后将自动开始)',
  379. style: TextStyle(fontSize: 12, fontWeight: FontWeight.normal),
  380. )
  381. ]),
  382. style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold),
  383. ),
  384. onPressed: () {
  385. if (widget.onStart != null) {
  386. widget.onStart();
  387. }
  388. },
  389. ),
  390. ),
  391. );
  392. }
  393. Widget countDownBtn() {
  394. final time = widget.houseInfo.createTime + 600000 - DateTime.now().millisecondsSinceEpoch;
  395. String text = '';
  396. if (time >= 0) {
  397. text = '预计${getCountDown(time)}后开始比赛';
  398. } else {
  399. text = '即将开始比赛';
  400. }
  401. return Container(
  402. margin: EdgeInsets.fromLTRB(15, 0, 15, 10),
  403. height: 48,
  404. color: PRIMARY_COLOR,
  405. child: Center(
  406. child: Text(
  407. text,
  408. style: TextStyle(
  409. color: Color(0xFF252532),
  410. fontSize: 16,
  411. fontWeight: FontWeight.bold,
  412. ),
  413. ),
  414. ),
  415. );
  416. }
  417. Widget statusBtn(text, {Color color = PRIMARY_COLOR}) {
  418. return Container(
  419. margin: EdgeInsets.fromLTRB(15, 0, 15, 10),
  420. height: 48,
  421. color: color,
  422. child: Center(
  423. child: Text(
  424. text,
  425. style: TextStyle(
  426. color: Color(0xFF252532),
  427. fontSize: 16,
  428. fontWeight: FontWeight.bold,
  429. ),
  430. ),
  431. ),
  432. );
  433. }
  434. String getCountDown(int time) {
  435. if (time == null) {
  436. return '';
  437. } else {
  438. return ((time ~/ 1000 ~/ 60) % 60).toString() + '分' + (time ~/ 1000 % 60).toString() + '秒';
  439. }
  440. }
  441. }