import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_redux/flutter_redux.dart'; import 'package:wanna_battle/net/HttpManager.dart'; import 'package:wanna_battle/redux/AppState.dart'; import 'package:wanna_battle/styles/totast.dart'; import '../Constants.dart'; import '../styles/colors.dart'; import '../widget/VideoWidget.dart'; import '../model/HouseInfo.dart'; import '../widget/Dialog.dart'; import './CompetitionNotice.dart'; import '../model/PlayerInfo.dart'; class RoomInfoDetail extends StatefulWidget { RoomInfoDetail(this.houseInfo, this.playerInfo, {Key key, this.onStart, this.finishedPlayerNum = 0}) : super(key: key); final HouseInfo houseInfo; final PlayerInfo playerInfo; final VoidCallback onStart; final int finishedPlayerNum; @override State createState() { return RoomInfoDetailState(); } } class RoomInfoDetailState extends State { String startCountDown; @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return Scaffold( body: Stack( children: [ ListView( children: [ widget.houseInfo != null ? VideoWidget(videoSrc: widget.houseInfo.video) : Container(), Container( height: 60, padding: EdgeInsets.fromLTRB(15, 0, 15, 0), child: Row( children: [ Expanded( child: Text( widget.houseInfo.houseName, style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.white), ), ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset( 'images/icon_renshu.png', width: 20, ), Text( (widget.houseInfo?.playerNumber ?? 0).toString() + '/' + (widget.houseInfo?.maxNumber ?? 0).toString(), style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: Color(0xFFB1B2C0)), ), ], ) ], ), ), Container( height: 40, margin: EdgeInsets.fromLTRB(15, 0, 15, 0), color: Color(0x1A1990F8), child: Row( children: [ Expanded( flex: 1, child: CupertinoButton( padding: EdgeInsets.all(0), onPressed: () { if (widget.houseInfo.statusFlag == 0) { showCustomDialog(context, '比赛即将开始,确定离开房间?', isCancel: true, onsubmit: () async { Toast.show(context, '退出房间', -1, 'loading'); await HttpManager.get('houseInfo/quitRoom', data: {'houseId': widget.houseInfo.id}); Toast.hide(); Navigator.of(context).pop(); }); } else { Navigator.of(context).pop(); } }, child: Text( '返回锦标赛', style: TextStyle(color: PRIMARY_COLOR, fontSize: 14, fontWeight: FontWeight.bold), ), ), ), Container( width: 1, height: 12, color: PRIMARY_COLOR, ), Expanded( flex: 1, child: CupertinoButton( padding: EdgeInsets.all(0), onPressed: () { showNotice(context); }, child: Text( '竞赛须知', style: TextStyle(color: PRIMARY_COLOR, fontSize: 14, fontWeight: FontWeight.bold), ), ), ), ], ), ), // Container( // height: 40, // margin: EdgeInsets.fromLTRB(15, 10, 15, 0), // decoration: BoxDecoration( // color: Color(0x1AFFFF00), // border: Border.all( // width: 1, // color: Colors.yellow, // )), // child: Row( // mainAxisAlignment: MainAxisAlignment.spaceAround, // children: [ // Text('积分 加成+0%', style: TextStyle(color: Colors.yellow, fontSize: 12)), // Text('保底 0积分', style: TextStyle(color: Colors.yellow, fontSize: 12)), // ], // ), // ), tipText() ], ), Align( alignment: Alignment.bottomCenter, child: SafeArea(child: roomBtn()), ) ], ), ); } Widget tipText() { switch (widget.houseInfo.statusFlag) { case HouseStatus.WAIT: case HouseStatus.READY: return Container( margin: EdgeInsets.fromLTRB(15, 20, 15, 0), color: SUB_COLOR, padding: EdgeInsets.all(15), child: Text.rich( TextSpan( text: '待倒计时结束或人数满员时会自动开启比赛,请在此页面耐心等待其他人的加入,' '祝您取得好成绩'), style: TextStyle(color: Colors.white, fontSize: 13), ), ); case HouseStatus.START: case HouseStatus.END: case HouseStatus.ANALYSIS: final time = widget.houseInfo.beginTime + 3600000 - DateTime.now().millisecondsSinceEpoch; return Container( margin: EdgeInsets.fromLTRB(15, 20, 15, 0), color: SUB_COLOR, padding: EdgeInsets.all(15), child: Text.rich( TextSpan(children: [ TextSpan(text: ((widget.playerInfo?.statusFlag ?? 0) == PlayerStatus.END) ? '你已完成本次比赛,当前完成人数' : '当前完成人数'), TextSpan(text: ' ${widget.finishedPlayerNum ?? 0} ', style: TextStyle(color: Colors.yellow, fontWeight: FontWeight.bold)), TextSpan(text: '比赛需要等待所有人完成后方可结算积分最迟结算时间还剩'), TextSpan(text: ' ${getCountDown(time)} ', style: TextStyle(color: Colors.yellow, fontWeight: FontWeight.bold)), TextSpan(text: ',你可以先去参加其他竞赛,稍后在“个人中心-我的战绩”中可以查看本次竞赛排名及积分详情'), ]), style: TextStyle(color: Colors.white, fontSize: 13), ), ); break; case HouseStatus.SETTLEMENT: return Column( children: [ (widget.playerInfo != null && widget.playerInfo.ranking != null && widget.playerInfo.liveTime != null && widget.playerInfo.score != null) ? Container( margin: EdgeInsets.fromLTRB(15, 20, 15, 0), color: SUB_COLOR, padding: EdgeInsets.fromLTRB(15, 15, 0, 15), child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text( '和平精英游戏结果', textAlign: TextAlign.left, style: TextStyle(color: Color(0x99FFFFFF)), ), Container( margin: EdgeInsets.only(top: 10), child: Row( children: [ Text( '名次', style: TextStyle(color: Colors.white, fontSize: 14), ), Expanded( child: Container( margin: EdgeInsets.only(left: 5), child: Text( widget.playerInfo?.ranking?.toString() ?? '', style: TextStyle(color: Colors.yellow, fontSize: 14, fontWeight: FontWeight.bold), ), ), ), Text( '时长', style: TextStyle(color: Colors.white, fontSize: 14), ), Expanded( child: Container( margin: EdgeInsets.only(left: 5), child: Text( widget.playerInfo?.liveTime != null ? (widget.playerInfo?.liveTime.toString() + '分钟') : '', style: TextStyle(color: Colors.yellow, fontSize: 14, fontWeight: FontWeight.bold), ), ), ), Text( '评分', style: TextStyle(color: Colors.white, fontSize: 14), ), Expanded( child: Container( margin: EdgeInsets.only(left: 5), child: Text( (widget.playerInfo?.score != null && widget.playerInfo.score > 0) ? widget.playerInfo.score.toString() : '', style: TextStyle(color: Colors.yellow, fontSize: 14, fontWeight: FontWeight.bold), ), ), ), ], ), ), ], ), ) : Container(height: 10), Container( margin: EdgeInsets.fromLTRB(15, 5, 15, 20), color: SUB_COLOR, padding: EdgeInsets.all(15), child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text( '比赛结果', textAlign: TextAlign.left, style: TextStyle(color: Color(0x99FFFFFF)), ), Container( margin: EdgeInsets.only(top: 10), child: Row( children: [ Expanded( child: Text( '参赛成员', style: TextStyle(color: Colors.white, fontSize: 14), textAlign: TextAlign.left, ), ), Text( widget.houseInfo?.playerNumber?.toString() ?? '', style: TextStyle(color: Colors.yellow, fontWeight: FontWeight.bold), ) ], ), ), Container( margin: EdgeInsets.only(top: 10), child: Row( children: [ Expanded( child: Text( '我的排名', style: TextStyle(color: Colors.white, fontSize: 14), textAlign: TextAlign.left, ), ), Text( widget.playerInfo?.houseRank?.toString() ?? '', style: TextStyle(color: Colors.yellow, fontWeight: FontWeight.bold), ) ], ), ), Container( margin: EdgeInsets.only(top: 10), child: Row( children: [ Expanded( child: Text( '本场比赛获得积分', style: TextStyle(color: Colors.white, fontSize: 14), textAlign: TextAlign.left, ), ), Container( margin: EdgeInsets.only(right: 3), width: 20, child: Image.asset('images/icon_jifen_da.png'), ), Text( widget.playerInfo?.points?.toString() ?? '0', style: TextStyle(color: Colors.yellow, fontWeight: FontWeight.bold), ) ], ), ), (widget.playerInfo?.ranking ?? 99) == 1 ? Container( margin: EdgeInsets.only(top: 5), child: Text( '吃鸡额外获得10积分', style: TextStyle(color: PRIMARY_COLOR, fontSize: 12), ), ) : Container() ], ), ) ], ); } return Container(); } Widget roomBtn() { switch (widget.houseInfo.statusFlag) { case HouseStatus.WAIT: case HouseStatus.READY: { if (widget.houseInfo.createUser == StoreProvider.of(context).state.userInfo.id.toString()) { return startBtn(); } else { return countDownBtn(); } } break; case HouseStatus.START: case HouseStatus.END: { final time = widget.houseInfo.beginTime + 3600000 - DateTime.now().millisecondsSinceEpoch; return statusBtn(time > 0 ? ('最迟在' + getCountDown(time) + '后结算') : '等待结算'); } break; case HouseStatus.SETTLEMENT: return statusBtn('已结束'); break; case HouseStatus.ANALYSIS: return statusBtn('结算中...'); default: return statusBtn('已结束', color: Color(0xFF4F5C87)); } } Widget startBtn() { final time = widget.houseInfo.createTime + 600000 - DateTime.now().millisecondsSinceEpoch; return Container( margin: EdgeInsets.fromLTRB(15, 0, 15, 10), child: SizedBox( height: 48, width: double.infinity, child: FlatButton( color: PRIMARY_COLOR, child: Text.rich( TextSpan(children: [ TextSpan( text: '开始比赛 ', style: TextStyle(fontSize: 16), ), TextSpan( text: '(${getCountDown(time)}后将自动开始)', style: TextStyle(fontSize: 12, fontWeight: FontWeight.normal), ) ]), style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold), ), onPressed: () { if (widget.onStart != null) { widget.onStart(); } }, ), ), ); } Widget countDownBtn() { final time = widget.houseInfo.createTime + 600000 - DateTime.now().millisecondsSinceEpoch; String text = ''; if (time >= 0) { text = '预计${getCountDown(time)}后开始比赛'; } else { text = '即将开始比赛'; } return Container( margin: EdgeInsets.fromLTRB(15, 0, 15, 10), height: 48, color: PRIMARY_COLOR, child: Center( child: Text( text, style: TextStyle( color: Color(0xFF252532), fontSize: 16, fontWeight: FontWeight.bold, ), ), ), ); } Widget statusBtn(text, {Color color = PRIMARY_COLOR}) { return Container( margin: EdgeInsets.fromLTRB(15, 0, 15, 10), height: 48, color: color, child: Center( child: Text( text, style: TextStyle( color: Color(0xFF252532), fontSize: 16, fontWeight: FontWeight.bold, ), ), ), ); } String getCountDown(int time) { if (time == null) { return ''; } else { return ((time ~/ 1000 ~/ 60) % 60).toString() + '分' + (time ~/ 1000 % 60).toString() + '秒'; } } }