import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:jpush_flutter/jpush_flutter.dart'; import 'package:shared_preferences/shared_preferences.dart'; class YSTabbar extends StatefulWidget { @override _YSPageState createState() => _YSPageState(); } class _YSPageState extends State { int _selectedIndex = 0; final JPush jpush = new JPush(); @override void initState() { Future _prefs = SharedPreferences.getInstance(); _prefs.then((value) => { if(value.getInt('chapters')==null){ value.setInt('chapters', 0), value.setInt('childId', 1), } }); 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(); } void onItemTap(int index){ setState(() { _selectedIndex = index; }); } @override Widget build(BuildContext context) { return CupertinoTabScaffold( tabBar: CupertinoTabBar( items: const[ BottomNavigationBarItem( icon: Icon(Icons.home), title: Text('首页') ), BottomNavigationBarItem( icon: Icon(Icons.calendar_today), title: Text('行程') ), BottomNavigationBarItem( icon: Icon(Icons.camera), title: Text('广场') ), BottomNavigationBarItem( icon: Icon(Icons.person), title: Text('我的') ), ], currentIndex: _selectedIndex, onTap: onItemTap, activeColor: Color(0xFF007AFF), inactiveColor: Color(0xFF999999), iconSize: 25, ), tabBuilder: (context,index){ return CupertinoTabView( builder: (context){ if (index == 0) { return null(); }else if(index == 1){ return null(); }else{ return null(); } }, ); }, ); } }