| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- 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<HomePage> with SingleTickerProviderStateMixin {
- int ts = 0;
- final List<Tab> myTabs = <Tab>[
- Tab(text: 'LEFT'),
- Tab(text: 'RIGHT'),
- ];
- final GlobalKey<UpgradeDialogState> _dialogKey = GlobalKey();
- TabController _tabController;
- int _selectedIndex = 0;
- final List<Widget> _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>[
- 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>[
- // 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<void> 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,
- ),
- ),
- );
- }
- }
- }
- }
|