Home.dart 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/services.dart';
  5. import 'package:shared_preferences/shared_preferences.dart';
  6. import 'package:wanna_battle/model/HouseInfo.dart';
  7. import 'package:wanna_battle/model/PlayerInfo.dart';
  8. import 'package:wanna_battle/net/Result.dart';
  9. import 'package:wanna_battle/styles/totast.dart';
  10. import './Competitions.dart';
  11. import '../widget/HomeDrawer.dart';
  12. import './TipList.dart';
  13. import './Shop.dart';
  14. import '../widget/CheckUpgrade.dart';
  15. import '../styles/colors.dart';
  16. import '../net/HttpManager.dart';
  17. import 'AppNotice.dart';
  18. import 'UserGuid.dart';
  19. import '../widget/Dialog.dart';
  20. import 'Appeal.dart';
  21. import 'RoomInfoNew.dart';
  22. class HomePage extends StatefulWidget {
  23. const HomePage({Key key}) : super(key: key);
  24. @override
  25. _HomePageState createState() => _HomePageState();
  26. }
  27. class _HomePageState extends State<HomePage> with SingleTickerProviderStateMixin {
  28. int ts = 0;
  29. final List<Tab> myTabs = <Tab>[
  30. Tab(text: 'LEFT'),
  31. Tab(text: 'RIGHT'),
  32. ];
  33. final GlobalKey<UpgradeDialogState> _dialogKey = GlobalKey();
  34. TabController _tabController;
  35. int _selectedIndex = 0;
  36. final List<Widget> _widgetOptions = [Competitions(key: PageStorageKey('page1')), TipList(key: PageStorageKey('page2')), Shop(key: PageStorageKey('page3'))];
  37. final PageStorageBucket bucket = PageStorageBucket();
  38. @override
  39. void initState() {
  40. super.initState();
  41. _tabController = TabController(vsync: this, length: myTabs.length);
  42. Future.delayed(Duration.zero, () async {
  43. final prefs = await SharedPreferences.getInstance();
  44. final bool showGuid1 = prefs.getBool('showGuid1') ?? true;
  45. if (showGuid1) {
  46. await prefs.setBool('showGuid1', false);
  47. await showUserGuide1(context);
  48. }
  49. getAppNotice(context);
  50. checkUpgrade(context, _dialogKey);
  51. checkErrorPlayerInfo();
  52. });
  53. }
  54. @override
  55. void dispose() {
  56. _tabController.dispose();
  57. super.dispose();
  58. }
  59. @override
  60. Widget build(BuildContext context) {
  61. return WillPopScope(
  62. child: Scaffold(
  63. drawer: HomeDrawer(),
  64. bottomNavigationBar: BottomNavigationBar(
  65. unselectedItemColor: Colors.white70,
  66. backgroundColor: Color(0xFF424767),
  67. currentIndex: _selectedIndex,
  68. items: const <BottomNavigationBarItem>[
  69. BottomNavigationBarItem(
  70. icon: ImageIcon(AssetImage('images/tabbar_icon_01.png'), size: 28),
  71. title: Text(
  72. '赛事',
  73. style: TextStyle(fontSize: 11),
  74. ),
  75. ),
  76. BottomNavigationBarItem(
  77. icon: ImageIcon(AssetImage('images/tabbar_icon_02.png'), size: 28),
  78. title: Text(
  79. '消息',
  80. style: TextStyle(fontSize: 11),
  81. ),
  82. ),
  83. BottomNavigationBarItem(
  84. icon: ImageIcon(AssetImage('images/tabbar_icon_03.png'), size: 28),
  85. title: Text(
  86. '商城',
  87. style: TextStyle(fontSize: 11),
  88. ),
  89. ),
  90. ],
  91. onTap: (int index) {
  92. if (index == 2) {
  93. Toast.show(context, '即将开放,敬请期待', 1500, 'info');
  94. return;
  95. }
  96. setState(() {
  97. _selectedIndex = index;
  98. });
  99. },
  100. ),
  101. body: PageStorage(bucket: bucket, child: _widgetOptions.elementAt(_selectedIndex)),
  102. // body: CupertinoTabScaffold(
  103. // tabBar: CupertinoTabBar(
  104. // currentIndex: _selectedIndex,
  105. // items: <BottomNavigationBarItem>[
  106. // BottomNavigationBarItem(
  107. // icon: Image.asset('images/tabbar_icon_01.png'),
  108. // activeIcon: Image.asset('images/tabbar_icon_01_pre.png'),
  109. // title: Text('赛事'),
  110. // ),
  111. // BottomNavigationBarItem(
  112. // icon: Image.asset('images/tabbar_icon_02.png'),
  113. // activeIcon: Image.asset('images/tabbar_icon_02_pre.png'),
  114. // title: Text('邮件'),
  115. // ),
  116. // BottomNavigationBarItem(
  117. // icon: Image.asset('images/tabbar_icon_03.png'),
  118. // activeIcon: Image.asset('images/tabbar_icon_03_pre.png'),
  119. // title: Text('商城'),
  120. // )
  121. // ],
  122. // backgroundColor: Color(0xff424767),
  123. // activeColor: Color(0xff1990F8),
  124. // onTap: (tabIndex) {
  125. // setState(() {
  126. // _selectedIndex = 1;
  127. // });
  128. // },
  129. // ),
  130. // tabBuilder: (BuildContext context, int index) {
  131. // switch (index) {
  132. // case 0:
  133. // return Competitions();
  134. // case 1:
  135. // return TipList();
  136. // case 2:
  137. // return Shop();
  138. // default:
  139. // return Competitions();
  140. // }
  141. // },
  142. // ),
  143. ),
  144. onWillPop: () {
  145. int _ts = DateTime.now().millisecondsSinceEpoch;
  146. if (_ts - ts < 1500) {
  147. SystemChannels.platform.invokeMethod('SystemNavigator.pop');
  148. } else {
  149. setState(() {
  150. ts = _ts;
  151. });
  152. Toast.show(context, '再按一次退出', 1000, 'info');
  153. }
  154. return Future.value(false);
  155. },
  156. );
  157. }
  158. Future<void> checkErrorPlayerInfo() async {
  159. final Result res = await HttpManager.get('playerInfo/getErrorPlayerInfo');
  160. if (res.success) {
  161. final PlayerInfo playerInfo = PlayerInfo.fromJson(res.data);
  162. final res1 = await HttpManager.get('houseInfo/getOne', data: {'id': playerInfo.houseId});
  163. if (res1.success && res1.data != null) {
  164. Navigator.push(
  165. context,
  166. CupertinoPageRoute(
  167. builder: (context) => RoomInfo(
  168. HouseInfo.fromJson(res1.data),
  169. playerInfo: playerInfo,
  170. interrupted: true,
  171. ),
  172. ),
  173. );
  174. }
  175. }
  176. }
  177. }