import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/services.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:wanna_battle/model/HouseInfo.dart'; import 'package:wanna_battle/model/PlayerInfo.dart'; import 'package:wanna_battle/net/Result.dart'; import 'package:wanna_battle/styles/totast.dart'; import './Competitions.dart'; import '../widget/HomeDrawer.dart'; import './TipList.dart'; import './Shop.dart'; import '../widget/CheckUpgrade.dart'; import '../styles/colors.dart'; import '../net/HttpManager.dart'; import 'AppNotice.dart'; import 'UserGuid.dart'; import '../widget/Dialog.dart'; import 'Appeal.dart'; import 'RoomInfoNew.dart'; class HomePage extends StatefulWidget { const HomePage({Key key}) : super(key: key); @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State with SingleTickerProviderStateMixin { int ts = 0; final List myTabs = [ Tab(text: 'LEFT'), Tab(text: 'RIGHT'), ]; final GlobalKey _dialogKey = GlobalKey(); TabController _tabController; int _selectedIndex = 0; final List _widgetOptions = [Competitions(key: PageStorageKey('page1')), TipList(key: PageStorageKey('page2')), Shop(key: PageStorageKey('page3'))]; final PageStorageBucket bucket = PageStorageBucket(); @override void initState() { super.initState(); _tabController = TabController(vsync: this, length: myTabs.length); Future.delayed(Duration.zero, () async { final prefs = await SharedPreferences.getInstance(); final bool showGuid1 = prefs.getBool('showGuid1') ?? true; if (showGuid1) { await prefs.setBool('showGuid1', false); await showUserGuide1(context); } getAppNotice(context); checkUpgrade(context, _dialogKey); checkErrorPlayerInfo(); }); } @override void dispose() { _tabController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return WillPopScope( child: Scaffold( drawer: HomeDrawer(), bottomNavigationBar: BottomNavigationBar( unselectedItemColor: Colors.white70, backgroundColor: Color(0xFF424767), currentIndex: _selectedIndex, items: const [ BottomNavigationBarItem( icon: ImageIcon(AssetImage('images/tabbar_icon_01.png'), size: 28), title: Text( '赛事', style: TextStyle(fontSize: 11), ), ), BottomNavigationBarItem( icon: ImageIcon(AssetImage('images/tabbar_icon_02.png'), size: 28), title: Text( '消息', style: TextStyle(fontSize: 11), ), ), BottomNavigationBarItem( icon: ImageIcon(AssetImage('images/tabbar_icon_03.png'), size: 28), title: Text( '商城', style: TextStyle(fontSize: 11), ), ), ], onTap: (int index) { if (index == 2) { Toast.show(context, '即将开放,敬请期待', 1500, 'info'); return; } setState(() { _selectedIndex = index; }); }, ), body: PageStorage(bucket: bucket, child: _widgetOptions.elementAt(_selectedIndex)), // body: CupertinoTabScaffold( // tabBar: CupertinoTabBar( // currentIndex: _selectedIndex, // items: [ // BottomNavigationBarItem( // icon: Image.asset('images/tabbar_icon_01.png'), // activeIcon: Image.asset('images/tabbar_icon_01_pre.png'), // title: Text('赛事'), // ), // BottomNavigationBarItem( // icon: Image.asset('images/tabbar_icon_02.png'), // activeIcon: Image.asset('images/tabbar_icon_02_pre.png'), // title: Text('邮件'), // ), // BottomNavigationBarItem( // icon: Image.asset('images/tabbar_icon_03.png'), // activeIcon: Image.asset('images/tabbar_icon_03_pre.png'), // title: Text('商城'), // ) // ], // backgroundColor: Color(0xff424767), // activeColor: Color(0xff1990F8), // onTap: (tabIndex) { // setState(() { // _selectedIndex = 1; // }); // }, // ), // tabBuilder: (BuildContext context, int index) { // switch (index) { // case 0: // return Competitions(); // case 1: // return TipList(); // case 2: // return Shop(); // default: // return Competitions(); // } // }, // ), ), onWillPop: () { int _ts = DateTime.now().millisecondsSinceEpoch; if (_ts - ts < 1500) { SystemChannels.platform.invokeMethod('SystemNavigator.pop'); } else { setState(() { ts = _ts; }); Toast.show(context, '再按一次退出', 1000, 'info'); } return Future.value(false); }, ); } Future checkErrorPlayerInfo() async { final Result res = await HttpManager.get('playerInfo/getErrorPlayerInfo'); if (res.success) { final PlayerInfo playerInfo = PlayerInfo.fromJson(res.data); final res1 = await HttpManager.get('houseInfo/getOne', data: {'id': playerInfo.houseId}); if (res1.success && res1.data != null) { Navigator.push( context, CupertinoPageRoute( builder: (context) => RoomInfo( HouseInfo.fromJson(res1.data), playerInfo: playerInfo, interrupted: true, ), ), ); } } } }