import 'dart:convert'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_screenutil/screenutil.dart'; import 'package:ysairplane2/code/YSCourse.dart'; import 'package:ysairplane2/code/YSCourseDetail.dart'; import 'package:ysairplane2/code/YSHome.dart'; import 'package:ysairplane2/code/YSMine.dart'; import 'package:ysairplane2/code/YSSquare.dart'; import 'package:ysairplane2/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: "1f929bc00dda1119b28577c1", //你自己应用的 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"); print('======================${message['extras']['cn.jpush.android.EXTRA']}'); Map value = jsonDecode('${message['extras']['cn.jpush.android.EXTRA']}'); print('======================${value['screct']}'); Navigator.of(context,rootNavigator: true).push( CupertinoPageRoute( builder: (context){ return YSCourseDetail(orderStr: '${value['screct']}',); } ) ); }, onReceiveMessage: (Map message) async { print("flutter onReceiveMessage: $message"); }, onReceiveNotificationAuthorization:(Map message) async { print("flutter onReceiveNotificationAuthorization: $message"); }); } on PlatformException { } super.initState(); } final pageController = PageController(); final List widgets = [YSHome(), YSCourse(), YSSquare(), YSMine()]; 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) { ScreenUtil.init(context,designSize: Size(750, 1624),allowFontScaling: false); 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: widgets, physics: NeverScrollableScrollPhysics(), // 禁止滑动 ), ), ); } } class ShowNotification extends Notification { bool isShow; ShowNotification(this.isShow); }