HomePage1.dart 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. import 'package:flutter/material.dart';
  2. import 'package:wanna_battle/model/PlayerInfo.dart';
  3. import '../widget/HomeDrawer.dart';
  4. import 'Appeal.dart';
  5. import 'CreateRoom.dart';
  6. import 'RoomList.dart';
  7. import 'RankList.dart';
  8. import 'RoomInfo.dart';
  9. import 'ShoppingMall.dart';
  10. import 'package:flutter/cupertino.dart';
  11. import 'package:flutter_swiper/flutter_swiper.dart';
  12. import '../model/GameInfoSeasons.dart';
  13. import '../styles/totast.dart';
  14. import '../net/HttpManager.dart';
  15. import '../net/Result.dart';
  16. import 'TipList.dart';
  17. import 'package:flutter_redux/flutter_redux.dart';
  18. import '../redux/AppState.dart';
  19. import 'Setting.dart';
  20. import '../widget/Dialog.dart';
  21. import '../pages/openRoom.dart';
  22. import 'GuidePage.dart';
  23. class HomePage extends StatefulWidget {
  24. @override
  25. _HomePageState createState() => _HomePageState();
  26. }
  27. class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
  28. List<GameInfoSeasons> seasonList = [];
  29. int nowIndex = 0;
  30. PageController _pageController;
  31. bool showBadge = false;
  32. Future<void> getSeasonInfo() async {
  33. Toast.show(context, '加载中', -1, 'loading');
  34. Result res = await HttpManager.get('gameInfo/seasons', data: {
  35. 'userId': StoreProvider.of<AppState>(context).state.userInfo.id,
  36. });
  37. Toast.hide();
  38. if (res.success) {
  39. List<GameInfoSeasons> list = [];
  40. for (var item in res.data) {
  41. list.add(GameInfoSeasons.fromJson(item));
  42. }
  43. setState(() {
  44. seasonList = list;
  45. });
  46. } else {}
  47. }
  48. void showBackDialog() {
  49. MyDialog.showDialog(context, '暂时没有进行中的房间,敬请期待...');
  50. // showDialog<Null>(
  51. // context: context,
  52. // barrierDismissible: false,
  53. // builder: (BuildContext context) {
  54. // return AlertDialog(
  55. // content: Container(
  56. // height: 50,
  57. // child: Text(
  58. // style: TextStyle(color: Colors.black),
  59. // ),
  60. // ),
  61. // actions: <Widget>[
  62. // FlatButton(
  63. // child: Text('确定'),
  64. // onPressed: () {
  65. // Navigator.of(context).pop();
  66. // },
  67. // ),
  68. // ],
  69. // );
  70. // },
  71. // ).then((val) {});
  72. }
  73. Future<void> getOneRoom() async {
  74. Toast.show(context, '加载中', -1, 'loading');
  75. Result res = await HttpManager.get('houseInfo/getOne', data: {'statusFlag': 0});
  76. Toast.hide();
  77. if (res.success) {
  78. if (res.data != null) {
  79. Navigator.push(context, CupertinoPageRoute(builder: (context) => RoomInfo(roomId: res.data['id'].toString())));
  80. } else {
  81. showBackDialog();
  82. }
  83. }
  84. }
  85. Future<void> getUnreadMsg() async {
  86. Result res = await HttpManager.get('systemNotice/unread', data: {'userId': StoreProvider.of<AppState>(context).state.userInfo.id, 'statusFlag': 0});
  87. if (res.success && res.data != null) {
  88. if (res.data > 0) {
  89. setState(() {
  90. showBadge = true;
  91. });
  92. } else {
  93. setState(() {
  94. showBadge = false;
  95. });
  96. }
  97. }
  98. }
  99. Future<void> checkErrorPlayerInfo() async {
  100. final Result res = await HttpManager.get('playerInfo/getErrorPlayerInfo');
  101. if (res.success) {
  102. final PlayerInfo playerInfo = PlayerInfo.fromJson(res.data);
  103. MyDialog.showDialog(
  104. context,
  105. '由于系统性能安全策略问题导致本次比赛结果上传失败,你可以上传本次比赛结果照片进行结果申诉',
  106. isCancel: true,
  107. onsubmit: () {
  108. Navigator.push(context, CupertinoPageRoute(builder: (context) => Appeal(playerInfo)));
  109. },
  110. );
  111. }
  112. }
  113. @override
  114. void initState() {
  115. super.initState();
  116. WidgetsBinding.instance.addObserver(this);
  117. _pageController = PageController(initialPage: 0);
  118. Future.delayed(Duration.zero, () {
  119. getSeasonInfo();
  120. getUnreadMsg();
  121. checkErrorPlayerInfo();
  122. });
  123. }
  124. @override
  125. void dispose() {
  126. super.dispose();
  127. WidgetsBinding.instance.removeObserver(this);
  128. }
  129. @override
  130. void didChangeAppLifecycleState(AppLifecycleState state) {
  131. if (state == AppLifecycleState.resumed) {
  132. getUnreadMsg();
  133. }
  134. }
  135. @override
  136. Widget build(BuildContext context) {
  137. return Scaffold(
  138. drawer: HomeDrawer(),
  139. body: WillPopScope(
  140. child: Container(
  141. width: double.infinity,
  142. height: double.infinity,
  143. decoration: BoxDecoration(
  144. gradient: LinearGradient(
  145. colors: [Color.fromARGB(255, 177, 59, 56), Color.fromARGB(255, 147, 64, 61)], begin: Alignment.topCenter, end: Alignment.bottomCenter)),
  146. child: SafeArea(
  147. child: centerWidget(context),
  148. ),
  149. ),
  150. onWillPop: () {
  151. return Future.value(true);
  152. },
  153. ),
  154. // floatingActionButton: floatWidget(),
  155. // floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
  156. );
  157. }
  158. Widget floatWidget() {
  159. return Container(
  160. decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(100)), border: Border.all(width: 1, color: Color(0xFF1B1C28))),
  161. width: 166,
  162. height: 166,
  163. margin: EdgeInsets.only(bottom: 84),
  164. child: CircleAvatar(
  165. backgroundImage: AssetImage('images/centerBtn.png'),
  166. child: ClipOval(
  167. child: Material(
  168. color: Colors.transparent,
  169. child: InkWell(
  170. child: Container(
  171. width: 166,
  172. height: 166,
  173. child: Center(
  174. child: UnconstrainedBox(
  175. child: Image.asset('images/join.png', width: 85),
  176. ),
  177. ),
  178. ),
  179. onTap: () {
  180. getOneRoom();
  181. },
  182. )))),
  183. );
  184. }
  185. Widget centerWidget(BuildContext context) {
  186. double width = MediaQuery.of(context).size.width;
  187. double height = MediaQuery.of(context).size.height;
  188. String endSTring = '';
  189. if (seasonList.isNotEmpty) {
  190. int _time = seasonList[nowIndex].competitionSeason.endTime - DateTime.now().millisecondsSinceEpoch;
  191. _time = _time ~/ 1000 ~/ 3600 ~/ 24;
  192. endSTring = '倒计时 ' + _time.toString() + ' 天';
  193. }
  194. return Column(
  195. children: <Widget>[
  196. Expanded(
  197. child: Stack(
  198. children: <Widget>[
  199. Container(
  200. child: seasonList.isNotEmpty
  201. ? Swiper(
  202. index: nowIndex,
  203. itemCount: seasonList.length,
  204. scrollDirection: Axis.horizontal,
  205. loop: false,
  206. onTap: (index) {
  207. Navigator.push(
  208. context,
  209. CupertinoPageRoute(
  210. builder: (context) =>
  211. RankList(raceId: seasonList[index].competitionSeason.id, gameId: seasonList[index].competitionSeason.gameId)));
  212. },
  213. onIndexChanged: (index) {
  214. setState(() {
  215. nowIndex = index;
  216. });
  217. },
  218. itemBuilder: (context, index) {
  219. return Center(
  220. child: Container(
  221. width: 0.64 * (height - 334),
  222. height: 0.64 * (height - 334),
  223. decoration: BoxDecoration(image: DecorationImage(image: AssetImage('images/home_icon_yuan.png'), fit: BoxFit.contain)),
  224. child: Column(
  225. mainAxisAlignment: MainAxisAlignment.center,
  226. children: <Widget>[
  227. Text('赛季奖金', style: TextStyle(color: Color(0xFFFFFFFF), fontSize: 13)),
  228. Container(
  229. height: 0.1 * (height - 334),
  230. ),
  231. Row(
  232. mainAxisAlignment: MainAxisAlignment.center,
  233. crossAxisAlignment: CrossAxisAlignment.end,
  234. children: _moneyList(),
  235. ),
  236. Container(
  237. height: 0.06 * (height - 334),
  238. ),
  239. Column(
  240. children: <Widget>[
  241. Text('当前排名', style: TextStyle(color: Color(0xFFFFFFFF), fontSize: 13)),
  242. Text(
  243. seasonList[index].competitionSeason.playerInfo.rank != null
  244. ? seasonList[index].competitionSeason.playerInfo.rank.toString()
  245. : '无排名',
  246. style: TextStyle(color: Color(0xFFFFFFFF), fontSize: 13))
  247. ],
  248. )
  249. ],
  250. ),
  251. ));
  252. },
  253. )
  254. : Container()),
  255. Positioned(
  256. left: 10,
  257. top: 0,
  258. width: 48,
  259. height: 48,
  260. child: Material(
  261. color: Colors.transparent,
  262. child: Builder(
  263. builder: (context) => InkWell(
  264. onTap: () {
  265. Scaffold.of(context).openDrawer();
  266. },
  267. child: Padding(
  268. padding: EdgeInsets.all(12),
  269. child: Image.asset(
  270. 'images/person.png',
  271. width: 24,
  272. ),
  273. ),
  274. ),
  275. ),
  276. ),
  277. ),
  278. Positioned(
  279. right: 10,
  280. top: 0,
  281. width: 48,
  282. height: 48,
  283. child: Material(
  284. color: Colors.transparent,
  285. child: InkWell(
  286. onTap: () {
  287. Navigator.push(context, CupertinoPageRoute(builder: (context) => Setting()));
  288. },
  289. child: Padding(
  290. padding: EdgeInsets.all(12),
  291. child: Image.asset('images/setting.png', width: 24),
  292. ),
  293. ),
  294. ),
  295. ),
  296. Positioned(
  297. top: 15,
  298. left: 0,
  299. right: 0,
  300. child: Column(
  301. mainAxisAlignment: MainAxisAlignment.center,
  302. crossAxisAlignment: CrossAxisAlignment.center,
  303. children: <Widget>[
  304. // Text(
  305. // seasonList.length > 0
  306. // ? seasonList[nowIndex].competitionSeason.season
  307. // : '',
  308. // style: TextStyle(color: Colors.white, fontSize: 14),
  309. // ),
  310. Text(
  311. seasonList.isNotEmpty ? seasonList[nowIndex].gameName : '',
  312. style: TextStyle(color: Colors.white, fontSize: 14),
  313. )
  314. ],
  315. ),
  316. ),
  317. Positioned(
  318. bottom: 20,
  319. left: 0,
  320. right: 0,
  321. child: Column(
  322. mainAxisAlignment: MainAxisAlignment.center,
  323. crossAxisAlignment: CrossAxisAlignment.center,
  324. children: <Widget>[
  325. Text(
  326. endSTring,
  327. style: TextStyle(color: Colors.white, fontSize: 14),
  328. )
  329. ],
  330. ),
  331. ),
  332. ],
  333. ),
  334. ),
  335. Builder(
  336. builder: (BuildContext context) {
  337. double aspectRatio = 1;
  338. aspectRatio = width / 334;
  339. return Container(
  340. child: GridView.count(
  341. physics: BouncingScrollPhysics(),
  342. shrinkWrap: true,
  343. crossAxisCount: 2,
  344. childAspectRatio: aspectRatio,
  345. children: <Widget>[
  346. HomeMenu(
  347. 'images/home_icon_01.png',
  348. '加入比赛',
  349. onTapHomeMenu: () {
  350. // Navigator.of(context).push(PageRouteBuilder(
  351. // opaque: false,
  352. // transitionDuration: Duration(milliseconds: 300),
  353. // transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
  354. // return FadeTransition(
  355. // opacity: CurvedAnimation(parent: animation, curve: Curves.linear),
  356. // child: child,
  357. // );
  358. // },
  359. // pageBuilder: (BuildContext context, _, __) {
  360. // return CreateRoom();
  361. // }));
  362. Navigator.push(context, CupertinoPageRoute(builder: (context) => RoomList()));
  363. },
  364. ),
  365. HomeMenu(
  366. 'images/home_icon_02.png',
  367. '发起赛事',
  368. onTapHomeMenu: () {
  369. Navigator.push(context, CupertinoPageRoute(builder: (context) => OpenRoom(roomFlag: '0')));
  370. },
  371. ),
  372. HomeMenu(
  373. 'images/home_icon_03.png',
  374. '系统通知',
  375. onTapHomeMenu: () async {
  376. bool result = await Navigator.push(context, CupertinoPageRoute(builder: (context) => TipList()));
  377. if (result) {
  378. getUnreadMsg();
  379. }
  380. },
  381. showBadge: showBadge,
  382. ),
  383. HomeMenu(
  384. 'images/home_icon_04.png',
  385. '充值',
  386. onTapHomeMenu: () {
  387. Navigator.push(context, CupertinoPageRoute(builder: (context) => ShoppingMall()));
  388. },
  389. ),
  390. ],
  391. ),
  392. );
  393. },
  394. ),
  395. ],
  396. );
  397. }
  398. List<Widget> _moneyList() {
  399. double height = MediaQuery.of(context).size.height;
  400. List<Widget> _list = [];
  401. String bouns = (seasonList[nowIndex].competitionSeason.bonus / 1000).toStringAsFixed(1);
  402. // String bouns = (900000000100 / 1000).toStringAsFixed(1);
  403. // print(bouns);
  404. // print(bouns.indexOf('.0'));
  405. if (bouns.indexOf('.0') != -1 || num.parse(bouns) > 999) {
  406. bouns = bouns.substring(0, bouns.length - 2);
  407. }
  408. List<String> _bounsList = bouns.split('');
  409. List<String> _imageList = [];
  410. for (var item in _bounsList) {
  411. switch (item) {
  412. case '0':
  413. _imageList.add('images/0.png');
  414. break;
  415. case '1':
  416. _imageList.add('images/1.png');
  417. break;
  418. case '2':
  419. _imageList.add('images/2.png');
  420. break;
  421. case '3':
  422. _imageList.add('images/3.png');
  423. break;
  424. case '4':
  425. _imageList.add('images/4.png');
  426. break;
  427. case '5':
  428. _imageList.add('images/5.png');
  429. break;
  430. case '6':
  431. _imageList.add('images/6.png');
  432. break;
  433. case '7':
  434. _imageList.add('images/7.png');
  435. break;
  436. case '8':
  437. _imageList.add('images/8.png');
  438. break;
  439. case '9':
  440. _imageList.add('images/9.png');
  441. break;
  442. case '.':
  443. _imageList.add('.');
  444. break;
  445. }
  446. }
  447. if (_bounsList.isEmpty) {
  448. _imageList.add('images/0.png');
  449. }
  450. for (var item in _imageList) {
  451. if (item != '.') {
  452. if (_imageList.length > 4) {
  453. double _scale = 1 - (_imageList.length - 4) * 0.2;
  454. _list.add(Image.asset(item, height: 0.18 * 0.64 * (height - 334) * _scale));
  455. } else {
  456. _list.add(Image.asset(item, height: 0.18 * 0.64 * (height - 334)));
  457. }
  458. // _list.add(Container(width: 5));
  459. } else {
  460. _list.add(Text(
  461. '.',
  462. style: TextStyle(color: Colors.white, fontSize: 36, fontFamily: 'DINEngschrift', height: 1),
  463. ));
  464. }
  465. }
  466. _list.add(Text(
  467. 'K',
  468. style: TextStyle(color: Colors.white, fontSize: 24, fontFamily: 'DINEngschrift', height: .5),
  469. ));
  470. return _list;
  471. }
  472. }
  473. typedef void OnTapHomeMenu();
  474. class HomeMenu extends StatelessWidget {
  475. final String icon;
  476. final String name;
  477. final OnTapHomeMenu onTapHomeMenu;
  478. final bool showBadge;
  479. HomeMenu(this.icon, this.name, {this.onTapHomeMenu, this.showBadge = false});
  480. @override
  481. Widget build(BuildContext context) {
  482. return Container(
  483. decoration: BoxDecoration(
  484. gradient: LinearGradient(
  485. begin: Alignment.topCenter,
  486. end: Alignment.bottomCenter,
  487. stops: [0.0, 0.01, 0.8],
  488. colors: [Color(0xFF7E89B7), Color(0xFF4E536F), Color(0xFF333558)])),
  489. child: Container(
  490. decoration: BoxDecoration(
  491. border: Border(
  492. // top: BorderSide(width: 2,color: Color(0xFF7E89B7)),
  493. left: BorderSide(width: 0.5, color: Color(0x80000000)),
  494. right: BorderSide(width: 0.5, color: Color(0x80000000)),
  495. bottom: BorderSide(width: 1, color: Color(0x80000000)))),
  496. child: Material(
  497. color: Colors.transparent,
  498. child: InkWell(
  499. onTap: onTapHomeMenu,
  500. child: Container(
  501. child: Column(
  502. mainAxisAlignment: MainAxisAlignment.center,
  503. crossAxisAlignment: CrossAxisAlignment.center,
  504. children: <Widget>[
  505. Image.asset(
  506. icon,
  507. fit: BoxFit.contain,
  508. ),
  509. Container(
  510. height: 5,
  511. ),
  512. Text(
  513. name,
  514. style: TextStyle(color: Colors.white, fontSize: 13),
  515. )
  516. ],
  517. ),
  518. ),
  519. ),
  520. ),
  521. ),
  522. );
  523. }
  524. }