123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- 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/YSTools.dart';
- import 'package:jpush_flutter/jpush_flutter.dart';
- // class YSTabbar extends StatefulWidget {
- // @override
- // _YSPageState createState() => _YSPageState();
- // }
- //
- // class _YSPageState extends State<YSTabbar> {
- // final JPush jpush = new JPush();
- // @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();
- // }
- // int _selected = 0;
- // Widget _selectedWidget = YSHome();
- // _onTap(int index) async{
- // if(index==3||index==2){
- // isLogin(context,login: (){
- // switch (index){
- // case 0:
- // _selectedWidget = YSHome();
- // break;
- // case 1:
- // _selectedWidget = YSCourse();
- // break;
- // case 2:
- // _selectedWidget = YSSquare();
- // break;
- // case 3:
- // _selectedWidget = YSMine();
- // break;
- // }
- // setState(() {
- // _selected = index;
- // });
- // });
- // }else{
- // switch (index){
- // case 0:
- // _selectedWidget = YSHome();
- // break;
- // case 1:
- // _selectedWidget = YSCourse();
- // break;
- // case 2:
- // _selectedWidget = YSSquare();
- // break;
- // case 3:
- // _selectedWidget = YSMine();
- // break;
- // }
- // setState(() {
- // _selected = index;
- // });
- // }
- //
- // }
- // @override
- // Widget build(BuildContext context) {
- // return Scaffold(
- // bottomNavigationBar: CupertinoTabBar(
- // items: [
- // BottomNavigationBarItem(
- // icon: ImageIcon(AssetImage('lib/images/home.png'),size: 20,),
- // title: Text('首页',style: TextStyle(fontWeight: FontWeight.bold),)
- // ),
- // BottomNavigationBarItem(
- // icon: ImageIcon(AssetImage('lib/images/course.png'),size: 20,),
- // title: Text('行程',style: TextStyle(fontWeight: FontWeight.bold),)
- // ),
- // BottomNavigationBarItem(
- // icon: Stack(
- // children: [
- // ImageIcon(AssetImage('lib/images/square.png'),size: 20,),
- // Container(
- // height: 10,
- // width: 10,
- // decoration: BoxDecoration(
- // color: Colors.red,
- // borderRadius: BorderRadius.all(Radius.circular(5))
- // ),
- // margin: EdgeInsets.only(left: 15),
- // )
- // ],
- // ),//
- // title: Text('广场',style: TextStyle(fontWeight: FontWeight.bold),)
- // ),
- // BottomNavigationBarItem(
- // icon: ImageIcon(AssetImage('lib/images/mine.png'),size: 20,),
- // title: Text('我的',style: TextStyle(fontWeight: FontWeight.bold),)
- // ),
- // ],
- // activeColor: Color(0xFF007AFF),
- // inactiveColor: Color(0xFF999999),
- // iconSize: 25,
- // onTap: _onTap,
- // currentIndex: _selected,
- // ),
- // body: _selectedWidget,
- // );
- // }
- // }
- class YSTabbar extends StatefulWidget {
- @override
- _MyHomePageState createState() => _MyHomePageState();
- }
- class _MyHomePageState extends State<YSTabbar> {
- final JPush jpush = new JPush();
- @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 items = [
- BottomNavigationBarItem(
- icon: ImageIcon(AssetImage('lib/images/home.png'),size: 20,),
- title: Text('首页',style: TextStyle(fontWeight: FontWeight.bold),),
- ),
- BottomNavigationBarItem(
- icon: ImageIcon(AssetImage('lib/images/course.png'),size: 20,),
- title: Text('行程',style: TextStyle(fontWeight: FontWeight.bold),)
- ),
- BottomNavigationBarItem(
- icon: Stack(
- children: [
- ImageIcon(AssetImage('lib/images/square.png'),size: 20,),
- Container(
- height: 10,
- width: 10,
- decoration: BoxDecoration(
- color: Colors.red,
- borderRadius: BorderRadius.all(Radius.circular(5))
- ),
- margin: EdgeInsets.only(left: 15),
- )
- ],
- ),//
- title: Text('广场',style: TextStyle(fontWeight: FontWeight.bold),)
- ),
- BottomNavigationBarItem(
- icon: ImageIcon(AssetImage('lib/images/mine.png'),size: 20,),
- title: Text('我的',style: TextStyle(fontWeight: FontWeight.bold),)
- ),
- ];
- final bodyList = [YSHome(), YSCourse(), YSSquare(), YSMine()];
- final pageController = PageController();
- int currentIndex = 0;
- void onTap(int index) {
- if(index==3||index==2){
- isLogin(context,login: (){
- pageController.jumpToPage(index);
- });
- }else{
- pageController.jumpToPage(index);
- }
- }
- void onPageChanged(int index) {
- if(index==3||index==2){
- isLogin(context,login: (){
- currentIndex = index;
- });
- }else{
- currentIndex = index;
- }
- setState(() {});
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- bottomNavigationBar: CupertinoTabBar(
- items: items,
- currentIndex: currentIndex,
- onTap: onTap,
- activeColor: Color(0xFF007AFF),
- inactiveColor: Color(0xFF999999),
- ),
- body: PageView(
- controller: pageController,
- onPageChanged: onPageChanged,
- children: bodyList,
- physics: NeverScrollableScrollPhysics(), // 禁止滑动
- )
- );
- }
- }
|