123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- 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<YSTabbar> {
- 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<String, dynamic> message) async {
- print("flutter onReceiveNotification: $message");
- },
- onOpenNotification: (Map<String, dynamic> message) async {
- print("flutter onOpenNotification: $message");
- // Navigator.of(context).push(
- // CupertinoPageRoute(
- // builder: (context){
- // return null;
- // }
- // )
- // );
- },
- onReceiveMessage: (Map<String, dynamic> message) async {
- print("flutter onReceiveMessage: $message");
- },
- onReceiveNotificationAuthorization:(Map<String, dynamic> 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<ShowNotification>(
- 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);
- }
|