|
|
@@ -0,0 +1,239 @@
|
|
|
+import 'package:flutter/material.dart';
|
|
|
+import 'package:flutter/widgets.dart';
|
|
|
+import 'package:wanna_battle/model/UserPlayTimes.dart';
|
|
|
+import '../model/CompetitionInfo.dart';
|
|
|
+import '../styles/colors.dart';
|
|
|
+import 'package:gradient_text/gradient_text.dart';
|
|
|
+import '../model/HouseInfo.dart';
|
|
|
+import '../net/HttpManager.dart';
|
|
|
+import '../net/Result.dart';
|
|
|
+
|
|
|
+class CompetitionRooms extends StatefulWidget {
|
|
|
+ CompetitionRooms(this.competitionInfo);
|
|
|
+
|
|
|
+ final CompetitionInfo competitionInfo;
|
|
|
+
|
|
|
+ @override
|
|
|
+ State<StatefulWidget> createState() {
|
|
|
+ return _CompetitionRoomsState(competitionInfo);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class _CompetitionRoomsState extends State<CompetitionRooms> {
|
|
|
+ _CompetitionRoomsState(this.competitionInfo);
|
|
|
+
|
|
|
+ final CompetitionInfo competitionInfo;
|
|
|
+ List<HouseInfo> houseList = [];
|
|
|
+ int restTimes = 0;
|
|
|
+
|
|
|
+ @override
|
|
|
+ void initState() {
|
|
|
+ super.initState();
|
|
|
+ Future.delayed(Duration.zero, () {
|
|
|
+ _getRooms();
|
|
|
+ _getPlayTimes();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ return Scaffold(
|
|
|
+ appBar: AppBar(
|
|
|
+ title: Text(competitionInfo.competitionName),
|
|
|
+ centerTitle: true,
|
|
|
+ elevation: 0,
|
|
|
+ actions: <Widget>[
|
|
|
+ GestureDetector(
|
|
|
+ onTap: () {},
|
|
|
+ child: Image.asset('images/icon_paihangbang.png'),
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ body: Column(
|
|
|
+ children: <Widget>[
|
|
|
+ Container(
|
|
|
+ color: SUB_COLOR,
|
|
|
+ height: 116,
|
|
|
+ child: Column(
|
|
|
+ mainAxisAlignment: MainAxisAlignment.center,
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
+ children: <Widget>[
|
|
|
+ Row(
|
|
|
+ mainAxisAlignment: MainAxisAlignment.center,
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.baseline,
|
|
|
+ textBaseline: TextBaseline.alphabetic,
|
|
|
+ children: <Widget>[
|
|
|
+ GradientText('¥',
|
|
|
+ gradient: LinearGradient(
|
|
|
+ colors: [Color(0xFFFFC84B), Color(0xFFA26A23)],
|
|
|
+ begin: Alignment.topCenter,
|
|
|
+ end: Alignment.bottomCenter,
|
|
|
+ ),
|
|
|
+ style: TextStyle(fontSize: 17),
|
|
|
+ textAlign: TextAlign.center),
|
|
|
+ GradientText(competitionInfo.bonus.toString().replaceAllMapped(RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'), (Match m) => '${m[1]},'),
|
|
|
+ gradient: LinearGradient(
|
|
|
+ colors: [Color(0xFFFFC84B), Color(0xFFA26A23)],
|
|
|
+ begin: Alignment.topCenter,
|
|
|
+ end: Alignment.bottomCenter,
|
|
|
+ ),
|
|
|
+ style: TextStyle(fontSize: 27),
|
|
|
+ textAlign: TextAlign.center),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ Container(
|
|
|
+ color: Colors.yellow,
|
|
|
+ margin: EdgeInsets.only(top: 10),
|
|
|
+ padding: EdgeInsets.fromLTRB(6, 1, 6, 2),
|
|
|
+ child: Text(
|
|
|
+ '剩余参赛次数 $restTimes次',
|
|
|
+ style: TextStyle(
|
|
|
+ color: Color(0xFF293354),
|
|
|
+ fontSize: 12,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Container(
|
|
|
+ margin: EdgeInsets.only(top: 10),
|
|
|
+ child: Text(
|
|
|
+ competitionInfo.intro ?? '',
|
|
|
+ style: TextStyle(
|
|
|
+ color: Color(0xADFFFFFF),
|
|
|
+ fontSize: 13,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Expanded(
|
|
|
+ child: ListView(
|
|
|
+ padding: EdgeInsets.only(bottom: 10),
|
|
|
+ children: houseList.map((f) => _Room(f)).toList(),
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<void> _getRooms() async {
|
|
|
+ final Result res = await HttpManager.get('houseInfo/all', data: {'competitionId': competitionInfo.id});
|
|
|
+ final List<HouseInfo> list = [];
|
|
|
+ if (res.success && res.data != null) {
|
|
|
+ for (var item in res.data) {
|
|
|
+ final HouseInfo _temHouse = HouseInfo.fromJson(item);
|
|
|
+ list.add(_temHouse);
|
|
|
+ }
|
|
|
+ setState(() {
|
|
|
+ houseList = list;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<void> _getPlayTimes() async {
|
|
|
+ final Result res = await HttpManager.get('playerInfo/getTodayPlayTimes');
|
|
|
+ if (res.success) {
|
|
|
+ int rest = 0;
|
|
|
+ UserPlayTimes userPlayTimes = UserPlayTimes.fromJson(res.data);
|
|
|
+ if (competitionInfo.type == 1) {
|
|
|
+ rest = userPlayTimes.totalNormal - userPlayTimes.usedNormal;
|
|
|
+ } else {
|
|
|
+ rest = userPlayTimes.totalAdvanced - userPlayTimes.usedAdvanced;
|
|
|
+ }
|
|
|
+ if (rest < 0) {
|
|
|
+ rest = 0;
|
|
|
+ }
|
|
|
+ setState(() {
|
|
|
+ restTimes = rest;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ print(res);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class _Room extends StatelessWidget {
|
|
|
+ _Room(this.houseInfo);
|
|
|
+ final HouseInfo houseInfo;
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ var status;
|
|
|
+ var borderColor;
|
|
|
+ var backgroundColor;
|
|
|
+ var imgSrc;
|
|
|
+ switch (houseInfo.statusFlag) {
|
|
|
+ case 0:
|
|
|
+ case 1:
|
|
|
+ status = '等待中';
|
|
|
+ borderColor = Color(0xFF1C62A7);
|
|
|
+ backgroundColor = Color(0x990D2F54);
|
|
|
+ imgSrc = 'images/icon_dengdaizhong.png';
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ status = '进行中';
|
|
|
+ borderColor = Color(0xFF8C8146);
|
|
|
+ backgroundColor = Color(0x990D2F54);
|
|
|
+ imgSrc = 'images/icon_jinxingzhong.png';
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ status = '已结束';
|
|
|
+ borderColor = Color(0xFF414854);
|
|
|
+ backgroundColor = Color(0xFF152536);
|
|
|
+ imgSrc = 'images/icon_yijiesu.png';
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return Container(
|
|
|
+ height: 43,
|
|
|
+ margin: EdgeInsets.fromLTRB(15, 10, 15, 0),
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ color: backgroundColor,
|
|
|
+ border: Border.all(color: borderColor, width: 2),
|
|
|
+ ),
|
|
|
+ child: Row(
|
|
|
+ children: <Widget>[
|
|
|
+ Expanded(
|
|
|
+ child: Container(
|
|
|
+ margin: EdgeInsets.only(left: 13),
|
|
|
+ child: Text(
|
|
|
+ houseInfo.houseName,
|
|
|
+ style: TextStyle(fontSize: 14, color: Colors.white),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Container(
|
|
|
+ width: 105,
|
|
|
+ child: RichText(
|
|
|
+ text: TextSpan(
|
|
|
+ style: TextStyle(color: Colors.white, fontSize: 11),
|
|
|
+ children: <TextSpan>[
|
|
|
+ TextSpan(text: '参赛人数:'),
|
|
|
+ TextSpan(text: houseInfo.playerNumber.toString(), style: TextStyle(color: Color(0xFF38A968))),
|
|
|
+ TextSpan(text: '/${houseInfo.maxNumber}'),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Container(
|
|
|
+ width: 60,
|
|
|
+ height: 43,
|
|
|
+ padding: EdgeInsets.only(left: 10),
|
|
|
+ alignment: Alignment.center,
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ image: DecorationImage(
|
|
|
+ image: AssetImage(imgSrc),
|
|
|
+ fit: BoxFit.cover,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ child: Text(
|
|
|
+ status,
|
|
|
+ style: TextStyle(
|
|
|
+ color: Colors.white,
|
|
|
+ fontSize: 14,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|