HomePage.dart 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:wanna_battle/model/PlayerInfo.dart';
  5. import 'package:shared_preferences/shared_preferences.dart';
  6. import 'package:flutter/cupertino.dart';
  7. import 'package:wanna_battle/model/PopNotice.dart';
  8. import 'GuidePage.dart';
  9. import 'MatchPage.dart';
  10. import 'RankList.dart';
  11. import '../widget/BottomTabs.dart';
  12. import 'UserPage.dart';
  13. import '../net/HttpManager.dart';
  14. import '../net/Result.dart';
  15. import 'RoomInfo.dart';
  16. import '../styles/totast.dart';
  17. import 'dart:async';
  18. import 'dart:ui';
  19. import '../model/PhoneInfo.dart';
  20. import 'PhoneLogin.dart';
  21. import '../model/PopNotice.dart';
  22. import '../utils/Utils.dart';
  23. class HomePage extends StatefulWidget {
  24. @override
  25. _HomePageState createState() => _HomePageState();
  26. }
  27. class _HomePageState extends State<HomePage> with SingleTickerProviderStateMixin {
  28. TabController controller;
  29. bool isFirst = true;
  30. bool showPage = false;
  31. List<PhoneInfo> phoneList;
  32. List<PopNotice> popNoticeList;
  33. Future<bool> getPhoneInfo() async {
  34. List<PhoneInfo> _phoneList = [];
  35. Result res = await HttpManager.get('phoneInfo/all');
  36. if (res.success && res.data != null) {
  37. for (var item in res.data) {
  38. PhoneInfo phone = PhoneInfo.fromJson(item);
  39. _phoneList.add(phone);
  40. }
  41. setState(() {
  42. phoneList = _phoneList;
  43. });
  44. }
  45. final prefs = await SharedPreferences.getInstance();
  46. var now = new DateTime.now();
  47. var timeStr = now.year.toString() + '/' + now.month.toString() + '/' + now.day.toString();
  48. prefs.setString('showPhoneInfo', timeStr);
  49. bool reslt = await Navigator.of(context).push(
  50. PageRouteBuilder(
  51. opaque: false,
  52. transitionDuration: Duration(milliseconds: 300),
  53. transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
  54. return FadeTransition(
  55. opacity: CurvedAnimation(parent: animation, curve: Curves.linear),
  56. child: child,
  57. );
  58. },
  59. pageBuilder: (BuildContext context, _, __) {
  60. return PhoneLogin(
  61. // text: '部分手机自动设置了省电策略,会将我们的app在游戏进程中从后台停掉,为了你的正常比赛,请点击你的手机型号查看具体设置',
  62. phoneList: phoneList,
  63. );
  64. },
  65. ),
  66. );
  67. if (reslt != null && reslt) {
  68. return true;
  69. } else {
  70. return false;
  71. }
  72. }
  73. Future<void> checkErrorPlayerInfo() async {
  74. popNoticeList = [];
  75. Result res1 = await HttpManager.get('popNotice/all');
  76. if (res1.success) {
  77. for (var item in res1.data) {
  78. popNoticeList.add(PopNotice.fromJson(item));
  79. }
  80. }
  81. final prefs = await SharedPreferences.getInstance();
  82. var now = new DateTime.now();
  83. var timeStr = now.year.toString() + '/' + now.month.toString() + '/' + now.day.toString();
  84. bool show = false;
  85. if (prefs.getString('showPhoneInfo') != timeStr && Platform.isAndroid) {
  86. await getPhoneInfo();
  87. }
  88. showGruide(context, popNoticeList);
  89. final Result res = await HttpManager.get('playerInfo/getErrorPlayerInfo');
  90. print('&********');
  91. print(res.error);
  92. if (res.success) {
  93. final PlayerInfo playerInfo = PlayerInfo.fromJson(res.data);
  94. // MyDialog.showDialog(
  95. // context,
  96. // '由于系统性能安全策略问题导致本次比赛结果上传失败,你可以上传本次比赛结果照片进行结果申诉',
  97. // isCancel: true,
  98. // onsubmit: () {
  99. // Navigator.push(context, CupertinoPageRoute(builder: (context) => Appeal(playerInfo)));
  100. // },
  101. // );
  102. final res1 = await HttpManager.get('houseInfo/getOne', data: {'id': playerInfo.houseId});
  103. if (res1.success && res1.data != null) {
  104. Navigator.push(
  105. context,
  106. CupertinoPageRoute(
  107. builder: (context) => RoomInfo(
  108. roomId: res1.data['id'].toString(),
  109. // playerInfo: playerInfo,
  110. // interrupted: true,
  111. ),
  112. ),
  113. );
  114. }
  115. } else {
  116. //引导页
  117. }
  118. }
  119. @override
  120. void initState() {
  121. super.initState();
  122. controller = new TabController(length: 3, vsync: this);
  123. Future.delayed(Duration.zero, () async {
  124. await checkErrorPlayerInfo();
  125. getVersion(context);
  126. });
  127. }
  128. @override
  129. void dispose() {
  130. controller.dispose();
  131. super.dispose();
  132. }
  133. @override
  134. Widget build(BuildContext context) {
  135. return Scaffold(
  136. backgroundColor: Color(0xFF2E3049),
  137. body: WillPopScope(
  138. child: Container(
  139. color: Color(0xFF2E3049),
  140. child: showPage
  141. ? MyTabBarView(
  142. controller: controller,
  143. children: <Widget>[MatchPage(), RankList(), UserPage()],
  144. )
  145. : Container(),
  146. ),
  147. onWillPop: () async {
  148. if (isFirst) {
  149. isFirst = false;
  150. Toast.show(context, '再次点击退出程序', 1000, 'info');
  151. Timer(Duration(seconds: 1), () {
  152. isFirst = true;
  153. });
  154. return Future.value(false);
  155. } else {
  156. return await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
  157. }
  158. },
  159. ),
  160. bottomNavigationBar: showPage
  161. ? Container(
  162. color: Color(0xFF23253C),
  163. height: 49,
  164. child: MyTabBar(
  165. controller: controller,
  166. labelColor: Theme.of(context).primaryColor,
  167. unselectedLabelColor: Color(0xFF46496C),
  168. indicatorColor: Color(0xFF171721),
  169. labelPadding: EdgeInsets.zero,
  170. labelStyle: TextStyle(fontSize: 11, height: 1),
  171. tabs: <Widget>[
  172. MyTab(
  173. text: "赛事",
  174. icon: ImageIcon(AssetImage('images/tabbar_icon_01_pre.png'), size: 28),
  175. ),
  176. MyTab(
  177. text: "排行",
  178. icon: ImageIcon(AssetImage('images/tabbar_icon_02.png'), size: 28),
  179. ),
  180. MyTab(
  181. text: "我的",
  182. icon: ImageIcon(AssetImage('images/tabbar_icon_03.png'), size: 28),
  183. ),
  184. ],
  185. ),
  186. )
  187. : Container()
  188. // floatingActionButton: floatWidget(),
  189. // floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
  190. );
  191. }
  192. Future<void> showGruide(BuildContext context, List<PopNotice> popNoticeList) async {
  193. bool res = await Navigator.of(context).push(PageRouteBuilder(
  194. opaque: false,
  195. transitionDuration: Duration(milliseconds: 300),
  196. transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
  197. return FadeTransition(
  198. opacity: CurvedAnimation(parent: animation, curve: Curves.linear),
  199. child: child,
  200. );
  201. },
  202. pageBuilder: (BuildContext context, _, __) {
  203. return GuidePage(popNoticeList);
  204. }));
  205. if (res != null && res) {
  206. setState(() {
  207. showPage = true;
  208. });
  209. }
  210. }
  211. }