import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:ysairplane/code/YSCourse.dart'; import 'package:ysairplane/code/YSHome.dart'; import 'package:ysairplane/code/YSLogin.dart'; import 'package:ysairplane/code/YSMine.dart'; import 'package:ysairplane/code/YSSquare.dart'; import 'package:ysairplane/tools/YSTools.dart'; import 'package:jpush_flutter/jpush_flutter.dart'; // class YSTabbar extends StatefulWidget { // @override // _YSPageState createState() => _YSPageState(); // } // // class _YSPageState extends State { // final JPush jpush = new JPush(); // @override // void initState() { // jpush.setup( // appKey: "5cdf5bc06073b6ba4b3eaf86", //你自己应用的 AppKey // channel: "theChannel", // production: false, // debug: true, // ); // jpush.applyPushAuthority( // new NotificationSettingsIOS(sound: true, alert: true, badge: true) // ); // jpush.getRegistrationID().then((rid) { // print("flutter get registration id : $rid"); // }); // try { // jpush.addEventHandler( // onReceiveNotification: (Map message) async { // print("flutter onReceiveNotification: $message"); // }, // onOpenNotification: (Map message) async { // print("flutter onOpenNotification: $message"); // // Navigator.of(context).push( // // CupertinoPageRoute( // // builder: (context){ // // return null; // // } // // ) // // ); // }, // onReceiveMessage: (Map message) async { // print("flutter onReceiveMessage: $message"); // }, // onReceiveNotificationAuthorization:(Map message) async { // print("flutter onReceiveNotificationAuthorization: $message"); // }); // } on PlatformException { // // } // // super.initState(); // } // int _selected = 0; // Widget _selectedWidget = YSHome(); // _onTap(int index) async{ // if(index==3||index==2){ // isLogin(context,login: (){ // switch (index){ // case 0: // _selectedWidget = YSHome(); // break; // case 1: // _selectedWidget = YSCourse(); // break; // case 2: // _selectedWidget = YSSquare(); // break; // case 3: // _selectedWidget = YSMine(); // break; // } // setState(() { // _selected = index; // }); // }); // }else{ // switch (index){ // case 0: // _selectedWidget = YSHome(); // break; // case 1: // _selectedWidget = YSCourse(); // break; // case 2: // _selectedWidget = YSSquare(); // break; // case 3: // _selectedWidget = YSMine(); // break; // } // setState(() { // _selected = index; // }); // } // // } // @override // Widget build(BuildContext context) { // return Scaffold( // bottomNavigationBar: CupertinoTabBar( // items: [ // BottomNavigationBarItem( // icon: ImageIcon(AssetImage('lib/images/home.png'),size: 20,), // title: Text('首页',style: TextStyle(fontWeight: FontWeight.bold),) // ), // BottomNavigationBarItem( // icon: ImageIcon(AssetImage('lib/images/course.png'),size: 20,), // title: Text('行程',style: TextStyle(fontWeight: FontWeight.bold),) // ), // BottomNavigationBarItem( // icon: Stack( // children: [ // ImageIcon(AssetImage('lib/images/square.png'),size: 20,), // Container( // height: 10, // width: 10, // decoration: BoxDecoration( // color: Colors.red, // borderRadius: BorderRadius.all(Radius.circular(5)) // ), // margin: EdgeInsets.only(left: 15), // ) // ], // ),// // title: Text('广场',style: TextStyle(fontWeight: FontWeight.bold),) // ), // BottomNavigationBarItem( // icon: ImageIcon(AssetImage('lib/images/mine.png'),size: 20,), // title: Text('我的',style: TextStyle(fontWeight: FontWeight.bold),) // ), // ], // activeColor: Color(0xFF007AFF), // inactiveColor: Color(0xFF999999), // iconSize: 25, // onTap: _onTap, // currentIndex: _selected, // ), // body: _selectedWidget, // ); // } // } class YSTabbar extends StatefulWidget { @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State { final JPush jpush = new JPush(); @override void initState() { jpush.setup( appKey: "5cdf5bc06073b6ba4b3eaf86", //你自己应用的 AppKey channel: "theChannel", production: false, debug: true, ); jpush.applyPushAuthority( new NotificationSettingsIOS(sound: true, alert: true, badge: true) ); jpush.getRegistrationID().then((rid) { print("flutter get registration id : $rid"); }); try { jpush.addEventHandler( onReceiveNotification: (Map message) async { print("flutter onReceiveNotification: $message"); }, onOpenNotification: (Map message) async { print("flutter onOpenNotification: $message"); // Navigator.of(context).push( // CupertinoPageRoute( // builder: (context){ // return null; // } // ) // ); }, onReceiveMessage: (Map message) async { print("flutter onReceiveMessage: $message"); }, onReceiveNotificationAuthorization:(Map message) async { print("flutter onReceiveNotificationAuthorization: $message"); }); } on PlatformException { } super.initState(); } final items = [ BottomNavigationBarItem( icon: ImageIcon(AssetImage('lib/images/home.png'),size: 20,), title: Text('首页',style: TextStyle(fontWeight: FontWeight.bold),), ), BottomNavigationBarItem( icon: ImageIcon(AssetImage('lib/images/course.png'),size: 20,), title: Text('行程',style: TextStyle(fontWeight: FontWeight.bold),) ), BottomNavigationBarItem( icon: Stack( children: [ ImageIcon(AssetImage('lib/images/square.png'),size: 20,), Container( height: 10, width: 10, decoration: BoxDecoration( color: Colors.red, borderRadius: BorderRadius.all(Radius.circular(5)) ), margin: EdgeInsets.only(left: 15), ) ], ),// title: Text('广场',style: TextStyle(fontWeight: FontWeight.bold),) ), BottomNavigationBarItem( icon: ImageIcon(AssetImage('lib/images/mine.png'),size: 20,), title: Text('我的',style: TextStyle(fontWeight: FontWeight.bold),) ), ]; final bodyList = [YSHome(), YSCourse(), YSSquare(), YSMine()]; final pageController = PageController(); int currentIndex = 0; void onTap(int index) { if(index==3||index==2){ isLogin(context,login: (){ pageController.jumpToPage(index); }); }else{ pageController.jumpToPage(index); } } void onPageChanged(int index) { if(index==3||index==2){ isLogin(context,login: (){ currentIndex = index; }); }else{ currentIndex = index; } setState(() {}); } @override Widget build(BuildContext context) { return Scaffold( bottomNavigationBar: CupertinoTabBar( items: items, currentIndex: currentIndex, onTap: onTap, activeColor: Color(0xFF007AFF), inactiveColor: Color(0xFF999999), ), body: PageView( controller: pageController, onPageChanged: onPageChanged, children: bodyList, physics: NeverScrollableScrollPhysics(), // 禁止滑动 ) ); } }