123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- 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<YSTabbar> {
- int _selectedIndex = 0;
- final JPush jpush = new JPush();
- @override
- void initState() {
- Future<SharedPreferences> _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<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();
- }
- void onItemTap(int index){
- setState(() {
- _selectedIndex = index;
- });
- }
- @override
- Widget build(BuildContext context) {
- return CupertinoTabScaffold(
- tabBar: CupertinoTabBar(
- items: const<BottomNavigationBarItem>[
- 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();
- }
- },
- );
- },
- );
- }
- }
|