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/YSFutureNetWork.dart'; import 'package:ysairplane/tools/YSTools.dart'; import 'package:jpush_flutter/jpush_flutter.dart'; class YSTabbar extends StatefulWidget { @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State { final JPush jpush = new JPush(); bool _isShow = true; @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 pageController = PageController(); int currentIndex = 0; void onTap(int index) { if(index==3||index==2||index==1){ isLogin(context,login: (){ if(index==2){ _isShow = false; } currentIndex = index; pageController.jumpToPage(index); }); }else{ if(index==2){ _isShow = false; } currentIndex = index; pageController.jumpToPage(index); } } void onPageChanged(int index) { if(index==3||index==2||index==1){ isLogin(context,login: (){ currentIndex = index; setState(() {}); }); }else{ currentIndex = index; setState(() {}); } } @override Widget build(BuildContext context) { return Scaffold( bottomNavigationBar: CupertinoTabBar( items: [ BottomNavigationBarItem( icon: ImageIcon(AssetImage('lib/images/home.png'),size: 20,), label: '首页', ), BottomNavigationBarItem( icon: ImageIcon(AssetImage('lib/images/course.png'),size: 20,), label: '行程' ), BottomNavigationBarItem( icon: Stack( children: [ ImageIcon(AssetImage('lib/images/square.png'),size: 20,), if(_isShow==true)Container( height: 10, width: 10, decoration: BoxDecoration( color: Colors.red, borderRadius: BorderRadius.all(Radius.circular(5)) ), margin: EdgeInsets.only(left: 15), ) ], ),// label: '广场' ), BottomNavigationBarItem( icon: ImageIcon(AssetImage('lib/images/mine.png'),size: 20,), label: '我的' ), ], currentIndex: currentIndex, onTap: onTap, activeColor: Color(0xFF007AFF), inactiveColor: Color(0xFF999999), ), body: NotificationListener( onNotification: (ShowNotification msg){ onTap(1); return true; }, child: PageView( controller: pageController, onPageChanged: onPageChanged, children: [YSHome(), YSCourse(), YSSquare(), YSMine()], physics: NeverScrollableScrollPhysics(), // 禁止滑动 ), ), ); } } class ShowNotification extends Notification { bool isShow; ShowNotification(this.isShow); }