| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- import 'package:cached_network_image/cached_network_image.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/widgets.dart';
- import 'package:flutter_redux/flutter_redux.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:wanna_battle/model/UserPlayTimes.dart';
- import 'package:wanna_battle/styles/totast.dart';
- import '../model/CompetitionInfo.dart';
- import '../styles/colors.dart';
- import '../model/HouseInfo.dart';
- import '../net/HttpManager.dart';
- import '../net/Result.dart';
- import './RoomInfoNew.dart';
- import '../redux/AppState.dart';
- import '../plugins/ScreenStramPlugin.dart';
- import './CompetitionRank.dart';
- import '../Constants.dart';
- import './CompetitionRank.dart';
- import 'CompetitionNotice.dart';
- import 'UserGuid.dart';
- class CompetitionRooms extends StatefulWidget {
- CompetitionRooms(this.competitionInfo);
- final CompetitionInfo competitionInfo;
- @override
- State<StatefulWidget> createState() {
- return _CompetitionRoomsState();
- }
- }
- class _CompetitionRoomsState extends State<CompetitionRooms> {
- List<HouseInfo> houseList = [];
- int restTimes = 0;
- @override
- void initState() {
- super.initState();
- Future.delayed(Duration.zero, () async {
- _getRooms();
- _getPlayTimes();
- final prefs = await SharedPreferences.getInstance();
- final bool showGuid2 = prefs.getBool('showGuid2') ?? true;
- if (showGuid2) {
- await prefs.setBool('showGuid2', false);
- await showUserGuide2(context);
- }
- // showNotice(context);
- });
- }
- @override
- Widget build(BuildContext context) {
- final appBar = AppBar(
- title: Text(widget.competitionInfo.competitionName),
- centerTitle: true,
- elevation: 0,
- backgroundColor: Colors.transparent,
- );
- return Scaffold(
- backgroundColor: Color(0xff19213B),
- body: Column(
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: <Widget>[
- Container(
- decoration: BoxDecoration(
- image: DecorationImage(
- image: NetworkImage(widget.competitionInfo.pic),
- fit: BoxFit.cover,
- )),
- height: MediaQuery.of(context).size.width * 200 / 375,
- padding: EdgeInsets.only(left: 15, right: 15),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: <Widget>[
- appBar,
- Expanded(
- child: Column(
- children: <Widget>[
- Container(
- child: Text(
- widget.competitionInfo.intro ?? '',
- style: TextStyle(
- color: Color(0xADFFFFFF),
- fontSize: 13,
- ),
- ),
- ),
- 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: Row(
- children: <Widget>[
- Expanded(
- child: MaterialButton(
- color: Color(0xFFE56B45),
- elevation: 0,
- highlightElevation: 0,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: <Widget>[
- Image.asset(
- 'images/icon_jiangpin.png',
- width: 19,
- ),
- Container(
- margin: EdgeInsets.only(left: 15),
- child: Text(
- '奖品规则',
- style: TextStyle(color: Colors.white, fontSize: 14),
- ),
- )
- ],
- ),
- onPressed: () {
- showBonus();
- },
- ),
- ),
- Container(width: 15),
- Expanded(
- child: MaterialButton(
- color: PRIMARY_COLOR,
- elevation: 0,
- highlightElevation: 0,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: <Widget>[
- Image.asset(
- 'images/icon_paihangbang.png',
- width: 19,
- ),
- Container(
- margin: EdgeInsets.only(left: 15),
- child: Text(
- '排行榜',
- style: TextStyle(color: Colors.white, fontSize: 14),
- ),
- )
- ],
- ),
- onPressed: () {
- Navigator.push(context, CupertinoPageRoute(builder: (context) => CompetitionRank(competitionId: widget.competitionInfo.id)));
- },
- ),
- )
- ],
- ),
- )
- ],
- ),
- )
- ],
- ),
- ),
- Expanded(
- child: RefreshIndicator(
- onRefresh: () {
- _getPlayTimes();
- return _getRooms();
- },
- 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': widget.competitionInfo.id,
- 'advancedQuery': ' AND_,status_flag_,!=_,' + HouseStatus.SETTLEMENT.toString(),
- });
- 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 (widget.competitionInfo.type == 1) {
- rest = userPlayTimes.totalNormal - userPlayTimes.usedNormal;
- } else {
- rest = userPlayTimes.totalAdvanced - userPlayTimes.usedAdvanced;
- }
- if (rest < 0) {
- rest = 0;
- }
- setState(() {
- restTimes = rest;
- });
- }
- print(res);
- }
- void showBonus() {
- showGeneralDialog(
- context: context,
- barrierDismissible: true,
- pageBuilder: (BuildContext buildContext, Animation<double> animation, Animation<double> secondaryAnimation) {
- return Center(
- child: Material(
- color: Colors.transparent,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Container(
- width: 270,
- padding: EdgeInsets.all(0),
- decoration: BoxDecoration(color: Color(0xE6293559), border: Border.all(width: 1, color: Color(0xFF1990F8))),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: <Widget>[
- Container(
- margin: EdgeInsets.only(top: 25),
- child: Text(
- '奖品规则',
- style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
- textAlign: TextAlign.center,
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 20, left: 20, right: 20),
- child: Text(
- '按照比赛周期内\n各个玩家累计积分排名发放奖金',
- style: TextStyle(color: Colors.white, fontSize: 14),
- textAlign: TextAlign.left,
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 10, bottom: 40),
- padding: EdgeInsets.only(left: 20, right: 20),
- child: Text(
- widget.competitionInfo.bonus ?? '',
- style: TextStyle(color: Colors.white, fontSize: 14),
- ),
- )
- ],
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 20),
- child: GestureDetector(
- child: Image.asset('images/icon_guanbi.png'),
- onTap: () {
- Navigator.of(context).pop();
- },
- ),
- )
- ],
- ),
- ),
- );
- },
- barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
- barrierColor: Colors.black87,
- transitionDuration: const Duration(milliseconds: 300),
- );
- }
- }
- 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 GestureDetector(
- onTap: () {
- joinRoom(context, houseInfo.id);
- },
- child: 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 ?? 0).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,
- ),
- ),
- )
- ],
- ),
- ),
- );
- }
- Future<void> joinRoom(context, houseId) async {
- final hasPermission = await ScreenStreamPlugin.checkPermission();
- if (!hasPermission) {
- showDialog(
- context: context,
- builder: (context) => AlertDialog(
- title: Text('需要悬浮窗权限'),
- contentTextStyle: TextStyle(color: Colors.black87),
- content: Text('请在点击确定后勾选"允许显示在其他应用的上层"'),
- actions: <Widget>[
- FlatButton(
- child: Text('确定'),
- onPressed: () {
- Navigator.of(context).pop();
- ScreenStreamPlugin.requestPermission();
- },
- ),
- ],
- ),
- );
- return;
- }
- // Navigator.push(context, CupertinoPageRoute(builder: (context) => RoomInfo(houseInfo)));
- Toast.show(context, '加载中', -1, 'loading');
- Result res = await HttpManager.post('houseInfo/join', data: {'houseId': houseId, 'userId': StoreProvider.of<AppState>(context).state.userInfo.id});
- Toast.hide();
- if (res.success) {
- Navigator.push(context, CupertinoPageRoute(builder: (context) => RoomInfo(houseInfo)));
- } else {
- Toast.show(context, res.error, 1500, 'info');
- }
- }
- }
|