| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- 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<StatefulWidget> createState() {
- return RoomInfoDetailState();
- }
- }
- class RoomInfoDetailState extends State<RoomInfoDetail> {
- String startCountDown;
- @override
- void initState() {
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: Stack(
- children: <Widget>[
- ListView(
- children: <Widget>[
- widget.houseInfo != null ? VideoWidget(videoSrc: widget.houseInfo.video) : Container(),
- Container(
- height: 60,
- padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
- child: Row(
- children: <Widget>[
- Expanded(
- child: Text(
- widget.houseInfo.houseName,
- style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.white),
- ),
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- 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: <Widget>[
- 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: <Widget>[
- // 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>[
- 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>[
- (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: <Widget>[
- Text(
- '和平精英游戏结果',
- textAlign: TextAlign.left,
- style: TextStyle(color: Color(0x99FFFFFF)),
- ),
- Container(
- margin: EdgeInsets.only(top: 10),
- child: Row(
- children: <Widget>[
- 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: <Widget>[
- Text(
- '比赛结果',
- textAlign: TextAlign.left,
- style: TextStyle(color: Color(0x99FFFFFF)),
- ),
- Container(
- margin: EdgeInsets.only(top: 10),
- child: Row(
- children: <Widget>[
- 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: <Widget>[
- 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: <Widget>[
- 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<AppState>(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() + '秒';
- }
- }
- }
|