HomePage2.dart 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. import 'package:flutter/material.dart';
  2. import '../widget/HomeDrawer.dart';
  3. import 'CreateRoom.dart';
  4. import 'RoomList.dart';
  5. import 'RankList.dart';
  6. import 'RoomInfo.dart';
  7. import 'ShoppingMall.dart';
  8. import 'package:flutter/cupertino.dart';
  9. import 'package:flutter_swiper/flutter_swiper.dart';
  10. import '../model/GameInfoSeasons.dart';
  11. import '../styles/totast.dart';
  12. import '../net/HttpManager.dart';
  13. import '../net/Result.dart';
  14. import 'TipList.dart';
  15. import 'package:flutter_redux/flutter_redux.dart';
  16. import '../redux/AppState.dart';
  17. import 'Setting.dart';
  18. import '../widget/Dialog.dart';
  19. import 'package:redux/redux.dart';
  20. import '../model/UserInfo.dart';
  21. import '../pages/openRoom.dart';
  22. class HomePage extends StatefulWidget {
  23. @override
  24. _HomePageState createState() => _HomePageState();
  25. }
  26. class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
  27. List<GameInfoSeasons> seasonList = [];
  28. int nowIndex = 0;
  29. PageController _pageController;
  30. bool showBadge = false;
  31. Future<void> getSeasonInfo() async {
  32. Toast.show(context, '加载中', -1, 'loading');
  33. Result res = await HttpManager.get('gameInfo/seasons', data: {
  34. 'userId': StoreProvider.of<AppState>(context).state.userInfo.id,
  35. });
  36. Toast.hide();
  37. if (res.success) {
  38. List<GameInfoSeasons> list = [];
  39. for (var item in res.data) {
  40. list.add(GameInfoSeasons.fromJson(item));
  41. }
  42. setState(() {
  43. seasonList = list;
  44. });
  45. } else {}
  46. }
  47. void showBackDialog() {
  48. MyDialog.showDialog(context, '暂时没有进行中的房间,敬请期待...');
  49. }
  50. Future<void> getOneRoom() async {
  51. Toast.show(context, '加载中', -1, 'loading');
  52. Result res =
  53. await HttpManager.get('houseInfo/getOne', data: {'statusFlag': 0});
  54. Toast.hide();
  55. if (res.success) {
  56. if (res.data != null) {
  57. Navigator.push(
  58. context,
  59. CupertinoPageRoute(
  60. builder: (context) =>
  61. RoomInfo(roomId: res.data['id'].toString())));
  62. } else {
  63. showBackDialog();
  64. }
  65. }
  66. }
  67. Future<void> getUnreadMsg() async {
  68. Result res = await HttpManager.get('systemNotice/unread', data: {
  69. 'userId': StoreProvider.of<AppState>(context).state.userInfo.id,
  70. 'statusFlag': 0
  71. });
  72. if (res.success && res.data != null) {
  73. if (res.data > 0) {
  74. setState(() {
  75. showBadge = true;
  76. });
  77. } else {
  78. setState(() {
  79. showBadge = false;
  80. });
  81. }
  82. }
  83. }
  84. @override
  85. void initState() {
  86. super.initState();
  87. WidgetsBinding.instance.addObserver(this);
  88. _pageController = PageController(initialPage: 0);
  89. Future.delayed(Duration.zero, () {
  90. getSeasonInfo();
  91. getUnreadMsg();
  92. });
  93. }
  94. @override
  95. void dispose() {
  96. super.dispose();
  97. WidgetsBinding.instance.removeObserver(this);
  98. }
  99. @override
  100. void didChangeAppLifecycleState(AppLifecycleState state) {
  101. if (state == AppLifecycleState.resumed) {
  102. getUnreadMsg();
  103. }
  104. }
  105. @override
  106. Widget build(BuildContext context) {
  107. return StoreConnector<AppState, UserInfo>(
  108. converter: (Store store) => store.state.userInfo,
  109. builder: (context, userInfo) {
  110. return Scaffold(
  111. drawer: HomeDrawer(),
  112. body: WillPopScope(
  113. child: Container(
  114. width: double.infinity,
  115. height: double.infinity,
  116. decoration: BoxDecoration(
  117. gradient: LinearGradient(
  118. colors: [
  119. Color(0xFFC0C0C0),
  120. Color(0xFF3D4043),
  121. Color(0xFF383C40)
  122. ],
  123. begin: Alignment.topCenter,
  124. end: Alignment.bottomCenter,
  125. stops: [0.0, 0.15, 1.0])),
  126. child: SafeArea(
  127. child: centerWidget(context, userInfo),
  128. ),
  129. ),
  130. onWillPop: () {
  131. return Future.value(true);
  132. },
  133. ),
  134. // floatingActionButton: floatWidget(),
  135. // floatingActionButtonLocation:
  136. // FloatingActionButtonLocation.centerDocked,
  137. );
  138. });
  139. }
  140. Widget floatWidget() {
  141. return Container(
  142. decoration: BoxDecoration(
  143. borderRadius: BorderRadius.all(Radius.circular(100)),
  144. border: Border.all(width: 1, color: Color(0xFF1B1C28))),
  145. width: 166,
  146. height: 166,
  147. margin: EdgeInsets.only(bottom: 84),
  148. child: CircleAvatar(
  149. backgroundImage: AssetImage('images/centerBtn.png'),
  150. child: ClipOval(
  151. child: Material(
  152. color: Colors.transparent,
  153. child: InkWell(
  154. child: Container(
  155. width: 166,
  156. height: 166,
  157. child: Center(
  158. child: UnconstrainedBox(
  159. child: Image.asset('images/join.png', width: 85),
  160. ),
  161. ),
  162. ),
  163. onTap: () {
  164. getOneRoom();
  165. },
  166. )))),
  167. );
  168. }
  169. Widget centerWidget(BuildContext context, UserInfo userInfo) {
  170. double width = MediaQuery.of(context).size.width;
  171. double height = MediaQuery.of(context).size.height;
  172. String endSTring = '';
  173. if (seasonList.isNotEmpty) {
  174. int _time = seasonList[nowIndex].competitionSeason.endTime -
  175. DateTime.now().millisecondsSinceEpoch;
  176. _time = _time ~/ 1000 ~/ 3600 ~/ 24;
  177. endSTring = _time.toString();
  178. }
  179. return Column(
  180. children: <Widget>[
  181. Expanded(
  182. child: Stack(
  183. children: <Widget>[
  184. Container(
  185. child: seasonList.isNotEmpty
  186. ? Swiper(
  187. index: nowIndex,
  188. itemCount: seasonList.length,
  189. scrollDirection: Axis.horizontal,
  190. loop: false,
  191. onTap: (index) {
  192. Navigator.push(
  193. context,
  194. CupertinoPageRoute(
  195. builder: (context) => RankList(
  196. raceId: seasonList[index]
  197. .competitionSeason
  198. .id,
  199. gameId: seasonList[index]
  200. .competitionSeason
  201. .gameId)));
  202. },
  203. onIndexChanged: (index) {
  204. setState(() {
  205. nowIndex = index;
  206. });
  207. },
  208. itemBuilder: (context, index) {
  209. return Center(
  210. child: Container(
  211. // width: 0.64 * (height - 334),
  212. // height: 0.64 * (height - 334),
  213. // decoration: BoxDecoration(image: DecorationImage(image: AssetImage('images/home_icon_yuan.png'), fit: BoxFit.contain)),
  214. child: Column(
  215. mainAxisAlignment: MainAxisAlignment.center,
  216. children: <Widget>[
  217. Container(
  218. width: double.infinity,
  219. height: 52,
  220. decoration: BoxDecoration(
  221. image: DecorationImage(
  222. image: AssetImage(
  223. 'images/img_guang_home.png'))),
  224. child: Text(
  225. '赛季奖金',
  226. style: TextStyle(
  227. color: Color(0xFFFFFFFF),
  228. fontSize: 26,
  229. fontFamily: 'Pangmen',
  230. ),
  231. textAlign: TextAlign.center,
  232. ),
  233. ),
  234. Row(
  235. mainAxisAlignment: MainAxisAlignment.center,
  236. crossAxisAlignment: CrossAxisAlignment.end,
  237. children: _moneyList(),
  238. ),
  239. Container(
  240. height: 15,
  241. ),
  242. seasonList[index]
  243. .competitionSeason
  244. .playerInfo
  245. .rank !=
  246. null
  247. ? Text(
  248. '当前排名 ' +
  249. seasonList[index]
  250. .competitionSeason
  251. .playerInfo
  252. .rank
  253. .toString(),
  254. style: TextStyle(
  255. color: Color(0xFFFFFFFF),
  256. fontSize: 24,
  257. fontFamily: 'Pangmen'))
  258. : Container(),
  259. Container(
  260. height: 12,
  261. ),
  262. Text.rich(TextSpan(
  263. children: [
  264. TextSpan(text: "倒计时 "),
  265. TextSpan(
  266. text: endSTring,
  267. style: TextStyle(fontSize: 27),
  268. ),
  269. TextSpan(
  270. text: ' 天',
  271. ),
  272. ],
  273. style: TextStyle(
  274. color: Color(0xFFFFFFFF),
  275. fontSize: 16,
  276. fontFamily: 'Pangmen')))
  277. // Container(
  278. // height: 0.06 * (height - 334),
  279. // ),
  280. // Column(
  281. // children: <Widget>[
  282. // Text('当前排名',
  283. // style: TextStyle(
  284. // color: Color(0xFFFFFFFF),
  285. // fontSize: 13)),
  286. // Text('2',
  287. // style: TextStyle(
  288. // color: Color(0xFFFFFFFF),
  289. // fontSize: 13))
  290. // ],
  291. // )
  292. ],
  293. ),
  294. ));
  295. },
  296. )
  297. : Container()),
  298. Positioned(
  299. left: 26,
  300. top: 10,
  301. width: 48,
  302. height: 48,
  303. child: Material(
  304. color: Colors.transparent,
  305. child: Builder(
  306. builder: (context) => InkWell(
  307. onTap: () {
  308. Scaffold.of(context).openDrawer();
  309. },
  310. child: Container(
  311. width: 48,
  312. height: 48,
  313. padding: EdgeInsets.all(5),
  314. decoration: BoxDecoration(
  315. gradient: LinearGradient(
  316. colors: [Color(0xFFFEFEFE), Color(0xFFBFBFBF)],
  317. begin: Alignment.topCenter,
  318. end: Alignment.bottomCenter,
  319. ),
  320. borderRadius:
  321. BorderRadius.all(Radius.circular(100)),
  322. boxShadow: [
  323. //阴影
  324. BoxShadow(
  325. color: Colors.black45,
  326. offset: Offset(0, 2.0),
  327. blurRadius: 6.0)
  328. ]),
  329. child: CircleAvatar(
  330. backgroundImage: NetworkImage(userInfo.icon),
  331. ),
  332. )),
  333. ),
  334. ),
  335. ),
  336. Positioned(
  337. right: 12,
  338. top: 0,
  339. width: 48,
  340. height: 48,
  341. child: Material(
  342. color: Colors.transparent,
  343. child: InkWell(
  344. onTap: () {
  345. Navigator.push(context,
  346. CupertinoPageRoute(builder: (context) => Setting()));
  347. },
  348. child: Padding(
  349. padding: EdgeInsets.all(12),
  350. child: Image.asset('images/setting.png', width: 19),
  351. ),
  352. ),
  353. ),
  354. ),
  355. ],
  356. ),
  357. ),
  358. Builder(
  359. builder: (BuildContext context) {
  360. double aspectRatio = 1;
  361. aspectRatio = width / 334;
  362. return Container(
  363. height: 338,
  364. padding: EdgeInsets.fromLTRB(16, 34, 16, 26),
  365. width: double.infinity,
  366. decoration: BoxDecoration(
  367. gradient: LinearGradient(
  368. colors: [
  369. Color(0xFF394247),
  370. Color(0xFF1C272D),
  371. Color(0xFF08141A)
  372. ],
  373. begin: Alignment.topCenter,
  374. end: Alignment.bottomCenter,
  375. )),
  376. child: Column(
  377. children: <Widget>[
  378. Container(
  379. width: double.infinity,
  380. height: 108,
  381. child: HomeMenu(
  382. '开始游戏',
  383. onTapHomeMenu: () {
  384. Navigator.push(
  385. context,
  386. CupertinoPageRoute(
  387. builder: (context) => RoomList()));
  388. },
  389. ),
  390. ),
  391. Container(
  392. height: 28,
  393. ),
  394. Row(
  395. children: <Widget>[
  396. Expanded(
  397. flex: 1,
  398. child: Column(
  399. children: <Widget>[
  400. Container(
  401. height: 67,
  402. child: HomeMenu(
  403. '新增',
  404. onTapHomeMenu: () {
  405. // Navigator.of(context).push(PageRouteBuilder(
  406. // opaque: false,
  407. // transitionDuration:
  408. // Duration(milliseconds: 300),
  409. // transitionsBuilder: (BuildContext context,
  410. // Animation<double> animation,
  411. // Animation<double> secondaryAnimation,
  412. // Widget child) {
  413. // return FadeTransition(
  414. // opacity: CurvedAnimation(
  415. // parent: animation,
  416. // curve: Curves.linear),
  417. // child: child,
  418. // );
  419. // },
  420. // pageBuilder:
  421. // (BuildContext context, _, __) {
  422. // return CreateRoom();
  423. // }));
  424. Navigator.push(
  425. context,
  426. CupertinoPageRoute(
  427. builder: (context) => OpenRoom(
  428. roomFlag: '0'
  429. )));
  430. },
  431. ),
  432. ),
  433. Container(
  434. height: 8,
  435. ),
  436. Container(
  437. height: 67,
  438. child: HomeMenu(
  439. '邮件',
  440. onTapHomeMenu: () {
  441. Navigator.push(
  442. context,
  443. CupertinoPageRoute(
  444. builder: (context) => TipList()));
  445. },
  446. ),
  447. )
  448. ],
  449. ),
  450. ),
  451. Container(
  452. width: 14,
  453. ),
  454. Expanded(
  455. flex: 1,
  456. child: Container(
  457. height: 142,
  458. child: HomeMenu(
  459. '商城',
  460. onTapHomeMenu: () {
  461. Navigator.push(
  462. context,
  463. CupertinoPageRoute(
  464. builder: (context) => ShoppingMall()));
  465. },
  466. ),
  467. ),
  468. )
  469. ],
  470. )
  471. ],
  472. ),
  473. );
  474. },
  475. ),
  476. ],
  477. );
  478. }
  479. List<Widget> _moneyList() {
  480. double height = MediaQuery.of(context).size.height;
  481. List<Widget> _list = [];
  482. String bouns = (seasonList[nowIndex].competitionSeason.bonus / 1000)
  483. .toStringAsFixed(1);
  484. // String bouns = (6002222100 / 1000).toStringAsFixed(1);
  485. // print(bouns);
  486. // print(bouns.indexOf('.0'));
  487. if (bouns.indexOf('.0') != -1 || num.parse(bouns) > 99) {
  488. bouns = bouns.substring(0, bouns.length - 2);
  489. }
  490. List<String> _bounsList = bouns.split('');
  491. List<String> _imageList = [];
  492. for (var item in _bounsList) {
  493. switch (item) {
  494. case '0':
  495. _imageList.add('images/0.png');
  496. break;
  497. case '1':
  498. _imageList.add('images/1.png');
  499. break;
  500. case '2':
  501. _imageList.add('images/2.png');
  502. break;
  503. case '3':
  504. _imageList.add('images/3.png');
  505. break;
  506. case '4':
  507. _imageList.add('images/4.png');
  508. break;
  509. case '5':
  510. _imageList.add('images/5.png');
  511. break;
  512. case '6':
  513. _imageList.add('images/6.png');
  514. break;
  515. case '7':
  516. _imageList.add('images/7.png');
  517. break;
  518. case '8':
  519. _imageList.add('images/8.png');
  520. break;
  521. case '9':
  522. _imageList.add('images/9.png');
  523. break;
  524. case '.':
  525. _imageList.add('kong');
  526. _imageList.add('images/dian.png');
  527. _imageList.add('kong');
  528. break;
  529. }
  530. }
  531. if (_bounsList.isEmpty) {
  532. _imageList.add('images/0.png');
  533. }
  534. for (var item in _imageList) {
  535. if (item == 'kong') {
  536. _list.add(Container(
  537. width: 5,
  538. ));
  539. } else {
  540. if (_bounsList.length > 4) {
  541. _list.add(Image.asset(item, height: 300 / _bounsList.length));
  542. } else {
  543. _list.add(Image.asset(item));
  544. }
  545. }
  546. // if (item != '.') {
  547. // // if (_imageList.length > 4) {
  548. // // double _scale = 1 - (_imageList.length - 4) * 0.2;
  549. // // _list.add(Image.asset(item, height: 0.18 * 0.64 * (height - 334) * _scale));
  550. // // } else {
  551. // // _list.add(Image.asset(item, height: 0.18 * 0.64 * (height - 334)));
  552. // // }
  553. // _list.add(Image.asset(item));
  554. // } else {
  555. // _list.add(Text(
  556. // '.',
  557. // style: TextStyle(color: Colors.white, fontSize: 36, fontFamily: 'DINEngschrift', height: 0),
  558. // ));
  559. // }
  560. }
  561. _list.add(Container(width: 5));
  562. if (_bounsList.length > 4) {
  563. _list.add(Image.asset('images/K.png', height: 300 / _bounsList.length));
  564. } else {
  565. _list.add(Image.asset('images/K.png'));
  566. }
  567. return _list;
  568. }
  569. }
  570. typedef void OnTapHomeMenu();
  571. class HomeMenu extends StatelessWidget {
  572. final String title;
  573. final OnTapHomeMenu onTapHomeMenu;
  574. final bool showBadge;
  575. HomeMenu(this.title, {this.onTapHomeMenu, this.showBadge = false});
  576. @override
  577. Widget build(BuildContext context) {
  578. return Container(
  579. padding: EdgeInsets.all(5),
  580. decoration: BoxDecoration(
  581. gradient: LinearGradient(
  582. begin: Alignment.topCenter,
  583. end: Alignment.bottomCenter,
  584. colors: [Color(0xFFDFCF74), Color(0xFF6FB692)])),
  585. child: Container(
  586. decoration: BoxDecoration(
  587. gradient: LinearGradient(
  588. begin: Alignment.topCenter,
  589. end: Alignment.bottomCenter,
  590. colors: [Color(0xFFFFC30F), Color(0xFFFFA54C)])),
  591. child: Material(
  592. color: Colors.transparent,
  593. child: InkWell(
  594. onTap: onTapHomeMenu,
  595. child: Container(
  596. child: Center(
  597. child: Text(
  598. title,
  599. style: TextStyle(
  600. color: Color(0xFFFFFFFF),
  601. fontSize: 43,
  602. fontFamily: 'Pangmen'),
  603. )),
  604. ),
  605. ),
  606. ),
  607. ),
  608. );
  609. }
  610. }