HomePage1.dart 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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. Navigator.of(context).push(PageRouteBuilder(
  123. opaque: false,
  124. transitionDuration: Duration(milliseconds: 300),
  125. transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
  126. return FadeTransition(
  127. opacity: CurvedAnimation(parent: animation, curve: Curves.linear),
  128. child: child,
  129. );
  130. },
  131. pageBuilder: (BuildContext context, _, __) {
  132. return GuidePage();
  133. }));
  134. });
  135. }
  136. @override
  137. void dispose() {
  138. super.dispose();
  139. WidgetsBinding.instance.removeObserver(this);
  140. }
  141. @override
  142. void didChangeAppLifecycleState(AppLifecycleState state) {
  143. if (state == AppLifecycleState.resumed) {
  144. getUnreadMsg();
  145. }
  146. }
  147. @override
  148. Widget build(BuildContext context) {
  149. return Scaffold(
  150. drawer: HomeDrawer(),
  151. body: WillPopScope(
  152. child: Container(
  153. width: double.infinity,
  154. height: double.infinity,
  155. decoration: BoxDecoration(
  156. gradient: LinearGradient(
  157. colors: [Color.fromARGB(255, 177, 59, 56), Color.fromARGB(255, 147, 64, 61)], begin: Alignment.topCenter, end: Alignment.bottomCenter)),
  158. child: SafeArea(
  159. child: centerWidget(context),
  160. ),
  161. ),
  162. onWillPop: () {
  163. return Future.value(true);
  164. },
  165. ),
  166. // floatingActionButton: floatWidget(),
  167. // floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
  168. );
  169. }
  170. Widget floatWidget() {
  171. return Container(
  172. decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(100)), border: Border.all(width: 1, color: Color(0xFF1B1C28))),
  173. width: 166,
  174. height: 166,
  175. margin: EdgeInsets.only(bottom: 84),
  176. child: CircleAvatar(
  177. backgroundImage: AssetImage('images/centerBtn.png'),
  178. child: ClipOval(
  179. child: Material(
  180. color: Colors.transparent,
  181. child: InkWell(
  182. child: Container(
  183. width: 166,
  184. height: 166,
  185. child: Center(
  186. child: UnconstrainedBox(
  187. child: Image.asset('images/join.png', width: 85),
  188. ),
  189. ),
  190. ),
  191. onTap: () {
  192. getOneRoom();
  193. },
  194. )))),
  195. );
  196. }
  197. Widget centerWidget(BuildContext context) {
  198. double width = MediaQuery.of(context).size.width;
  199. double height = MediaQuery.of(context).size.height;
  200. String endSTring = '';
  201. if (seasonList.isNotEmpty) {
  202. int _time = seasonList[nowIndex].competitionSeason.endTime - DateTime.now().millisecondsSinceEpoch;
  203. _time = _time ~/ 1000 ~/ 3600 ~/ 24;
  204. endSTring = '倒计时 ' + _time.toString() + ' 天';
  205. }
  206. return Column(
  207. children: <Widget>[
  208. Expanded(
  209. child: Stack(
  210. children: <Widget>[
  211. Container(
  212. child: seasonList.isNotEmpty
  213. ? Swiper(
  214. index: nowIndex,
  215. itemCount: seasonList.length,
  216. scrollDirection: Axis.horizontal,
  217. loop: false,
  218. onTap: (index) {
  219. Navigator.push(
  220. context,
  221. CupertinoPageRoute(
  222. builder: (context) =>
  223. RankList(raceId: seasonList[index].competitionSeason.id, gameId: seasonList[index].competitionSeason.gameId)));
  224. },
  225. onIndexChanged: (index) {
  226. setState(() {
  227. nowIndex = index;
  228. });
  229. },
  230. itemBuilder: (context, index) {
  231. return Center(
  232. child: Container(
  233. width: 0.64 * (height - 334),
  234. height: 0.64 * (height - 334),
  235. decoration: BoxDecoration(image: DecorationImage(image: AssetImage('images/home_icon_yuan.png'), fit: BoxFit.contain)),
  236. child: Column(
  237. mainAxisAlignment: MainAxisAlignment.center,
  238. children: <Widget>[
  239. Text('赛季奖金', style: TextStyle(color: Color(0xFFFFFFFF), fontSize: 13)),
  240. Container(
  241. height: 0.1 * (height - 334),
  242. ),
  243. Row(
  244. mainAxisAlignment: MainAxisAlignment.center,
  245. crossAxisAlignment: CrossAxisAlignment.end,
  246. children: _moneyList(),
  247. ),
  248. Container(
  249. height: 0.06 * (height - 334),
  250. ),
  251. Column(
  252. children: <Widget>[
  253. Text('当前排名', style: TextStyle(color: Color(0xFFFFFFFF), fontSize: 13)),
  254. Text(
  255. seasonList[index].competitionSeason.playerInfo.rank != null
  256. ? seasonList[index].competitionSeason.playerInfo.rank.toString()
  257. : '无排名',
  258. style: TextStyle(color: Color(0xFFFFFFFF), fontSize: 13))
  259. ],
  260. )
  261. ],
  262. ),
  263. ));
  264. },
  265. )
  266. : Container()),
  267. Positioned(
  268. left: 10,
  269. top: 0,
  270. width: 48,
  271. height: 48,
  272. child: Material(
  273. color: Colors.transparent,
  274. child: Builder(
  275. builder: (context) => InkWell(
  276. onTap: () {
  277. Scaffold.of(context).openDrawer();
  278. },
  279. child: Padding(
  280. padding: EdgeInsets.all(12),
  281. child: Image.asset(
  282. 'images/person.png',
  283. width: 24,
  284. ),
  285. ),
  286. ),
  287. ),
  288. ),
  289. ),
  290. Positioned(
  291. right: 10,
  292. top: 0,
  293. width: 48,
  294. height: 48,
  295. child: Material(
  296. color: Colors.transparent,
  297. child: InkWell(
  298. onTap: () {
  299. Navigator.push(context, CupertinoPageRoute(builder: (context) => Setting()));
  300. },
  301. child: Padding(
  302. padding: EdgeInsets.all(12),
  303. child: Image.asset('images/setting.png', width: 24),
  304. ),
  305. ),
  306. ),
  307. ),
  308. Positioned(
  309. top: 15,
  310. left: 0,
  311. right: 0,
  312. child: Column(
  313. mainAxisAlignment: MainAxisAlignment.center,
  314. crossAxisAlignment: CrossAxisAlignment.center,
  315. children: <Widget>[
  316. // Text(
  317. // seasonList.length > 0
  318. // ? seasonList[nowIndex].competitionSeason.season
  319. // : '',
  320. // style: TextStyle(color: Colors.white, fontSize: 14),
  321. // ),
  322. Text(
  323. seasonList.isNotEmpty ? seasonList[nowIndex].gameName : '',
  324. style: TextStyle(color: Colors.white, fontSize: 14),
  325. )
  326. ],
  327. ),
  328. ),
  329. Positioned(
  330. bottom: 20,
  331. left: 0,
  332. right: 0,
  333. child: Column(
  334. mainAxisAlignment: MainAxisAlignment.center,
  335. crossAxisAlignment: CrossAxisAlignment.center,
  336. children: <Widget>[
  337. Text(
  338. endSTring,
  339. style: TextStyle(color: Colors.white, fontSize: 14),
  340. )
  341. ],
  342. ),
  343. ),
  344. ],
  345. ),
  346. ),
  347. Builder(
  348. builder: (BuildContext context) {
  349. double aspectRatio = 1;
  350. aspectRatio = width / 334;
  351. return Container(
  352. child: GridView.count(
  353. physics: BouncingScrollPhysics(),
  354. shrinkWrap: true,
  355. crossAxisCount: 2,
  356. childAspectRatio: aspectRatio,
  357. children: <Widget>[
  358. HomeMenu(
  359. 'images/home_icon_01.png',
  360. '加入比赛',
  361. onTapHomeMenu: () {
  362. // Navigator.of(context).push(PageRouteBuilder(
  363. // opaque: false,
  364. // transitionDuration: Duration(milliseconds: 300),
  365. // transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
  366. // return FadeTransition(
  367. // opacity: CurvedAnimation(parent: animation, curve: Curves.linear),
  368. // child: child,
  369. // );
  370. // },
  371. // pageBuilder: (BuildContext context, _, __) {
  372. // return CreateRoom();
  373. // }));
  374. Navigator.push(context, CupertinoPageRoute(builder: (context) => RoomList()));
  375. },
  376. ),
  377. HomeMenu(
  378. 'images/home_icon_02.png',
  379. '发起赛事',
  380. onTapHomeMenu: () {
  381. Navigator.push(context, CupertinoPageRoute(builder: (context) => OpenRoom(roomFlag: '0')));
  382. },
  383. ),
  384. HomeMenu(
  385. 'images/home_icon_03.png',
  386. '系统通知',
  387. onTapHomeMenu: () async {
  388. bool result = await Navigator.push(context, CupertinoPageRoute(builder: (context) => TipList()));
  389. if (result) {
  390. getUnreadMsg();
  391. }
  392. },
  393. showBadge: showBadge,
  394. ),
  395. HomeMenu(
  396. 'images/home_icon_04.png',
  397. '充值',
  398. onTapHomeMenu: () {
  399. Navigator.push(context, CupertinoPageRoute(builder: (context) => ShoppingMall()));
  400. },
  401. ),
  402. ],
  403. ),
  404. );
  405. },
  406. ),
  407. ],
  408. );
  409. }
  410. List<Widget> _moneyList() {
  411. double height = MediaQuery.of(context).size.height;
  412. List<Widget> _list = [];
  413. String bouns = (seasonList[nowIndex].competitionSeason.bonus / 1000).toStringAsFixed(1);
  414. // String bouns = (900000000100 / 1000).toStringAsFixed(1);
  415. // print(bouns);
  416. // print(bouns.indexOf('.0'));
  417. if (bouns.indexOf('.0') != -1 || num.parse(bouns) > 999) {
  418. bouns = bouns.substring(0, bouns.length - 2);
  419. }
  420. List<String> _bounsList = bouns.split('');
  421. List<String> _imageList = [];
  422. for (var item in _bounsList) {
  423. switch (item) {
  424. case '0':
  425. _imageList.add('images/0.png');
  426. break;
  427. case '1':
  428. _imageList.add('images/1.png');
  429. break;
  430. case '2':
  431. _imageList.add('images/2.png');
  432. break;
  433. case '3':
  434. _imageList.add('images/3.png');
  435. break;
  436. case '4':
  437. _imageList.add('images/4.png');
  438. break;
  439. case '5':
  440. _imageList.add('images/5.png');
  441. break;
  442. case '6':
  443. _imageList.add('images/6.png');
  444. break;
  445. case '7':
  446. _imageList.add('images/7.png');
  447. break;
  448. case '8':
  449. _imageList.add('images/8.png');
  450. break;
  451. case '9':
  452. _imageList.add('images/9.png');
  453. break;
  454. case '.':
  455. _imageList.add('.');
  456. break;
  457. }
  458. }
  459. if (_bounsList.isEmpty) {
  460. _imageList.add('images/0.png');
  461. }
  462. for (var item in _imageList) {
  463. if (item != '.') {
  464. if (_imageList.length > 4) {
  465. double _scale = 1 - (_imageList.length - 4) * 0.2;
  466. _list.add(Image.asset(item, height: 0.18 * 0.64 * (height - 334) * _scale));
  467. } else {
  468. _list.add(Image.asset(item, height: 0.18 * 0.64 * (height - 334)));
  469. }
  470. // _list.add(Container(width: 5));
  471. } else {
  472. _list.add(Text(
  473. '.',
  474. style: TextStyle(color: Colors.white, fontSize: 36, fontFamily: 'DINEngschrift', height: 1),
  475. ));
  476. }
  477. }
  478. _list.add(Text(
  479. 'K',
  480. style: TextStyle(color: Colors.white, fontSize: 24, fontFamily: 'DINEngschrift', height: .5),
  481. ));
  482. return _list;
  483. }
  484. }
  485. typedef void OnTapHomeMenu();
  486. class HomeMenu extends StatelessWidget {
  487. final String icon;
  488. final String name;
  489. final OnTapHomeMenu onTapHomeMenu;
  490. final bool showBadge;
  491. HomeMenu(this.icon, this.name, {this.onTapHomeMenu, this.showBadge = false});
  492. @override
  493. Widget build(BuildContext context) {
  494. return Container(
  495. decoration: BoxDecoration(
  496. gradient: LinearGradient(
  497. begin: Alignment.topCenter,
  498. end: Alignment.bottomCenter,
  499. stops: [0.0, 0.01, 0.8],
  500. colors: [Color(0xFF7E89B7), Color(0xFF4E536F), Color(0xFF333558)])),
  501. child: Container(
  502. decoration: BoxDecoration(
  503. border: Border(
  504. // top: BorderSide(width: 2,color: Color(0xFF7E89B7)),
  505. left: BorderSide(width: 0.5, color: Color(0x80000000)),
  506. right: BorderSide(width: 0.5, color: Color(0x80000000)),
  507. bottom: BorderSide(width: 1, color: Color(0x80000000)))),
  508. child: Material(
  509. color: Colors.transparent,
  510. child: InkWell(
  511. onTap: onTapHomeMenu,
  512. child: Container(
  513. child: Column(
  514. mainAxisAlignment: MainAxisAlignment.center,
  515. crossAxisAlignment: CrossAxisAlignment.center,
  516. children: <Widget>[
  517. Image.asset(
  518. icon,
  519. fit: BoxFit.contain,
  520. ),
  521. Container(
  522. height: 5,
  523. ),
  524. Text(
  525. name,
  526. style: TextStyle(color: Colors.white, fontSize: 13),
  527. )
  528. ],
  529. ),
  530. ),
  531. ),
  532. ),
  533. ),
  534. );
  535. }
  536. }