YSTabbar.dart 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import 'dart:convert';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/services.dart';
  5. import 'package:flutter_screenutil/screenutil.dart';
  6. import 'package:ysairplane2/code/YSCourse.dart';
  7. import 'package:ysairplane2/code/YSCourseDetail.dart';
  8. import 'package:ysairplane2/code/YSHome.dart';
  9. import 'package:ysairplane2/code/YSMine.dart';
  10. import 'package:ysairplane2/code/YSSquare.dart';
  11. import 'package:ysairplane2/tools/YSTools.dart';
  12. import 'package:jpush_flutter/jpush_flutter.dart';
  13. class YSTabbar extends StatefulWidget {
  14. @override
  15. _MyHomePageState createState() => _MyHomePageState();
  16. }
  17. class _MyHomePageState extends State<YSTabbar> {
  18. final JPush jpush = new JPush();
  19. bool _isShow = true;
  20. @override
  21. void initState() {
  22. jpush.setup(
  23. appKey: "1f929bc00dda1119b28577c1", //你自己应用的 AppKey
  24. channel: "theChannel",
  25. production: false,
  26. debug: true,
  27. );
  28. jpush.applyPushAuthority(
  29. new NotificationSettingsIOS(sound: true, alert: true, badge: true)
  30. );
  31. jpush.getRegistrationID().then((rid) {
  32. print("flutter get registration id : $rid");
  33. });
  34. try {
  35. jpush.addEventHandler(
  36. onReceiveNotification: (Map<String, dynamic> message) async {
  37. print("flutter onReceiveNotification: $message");
  38. },
  39. onOpenNotification: (Map<String, dynamic> message) async {
  40. print("flutter onOpenNotification: $message");
  41. print('======================${message['extras']['cn.jpush.android.EXTRA']}');
  42. Map value = jsonDecode('${message['extras']['cn.jpush.android.EXTRA']}');
  43. print('======================${value['screct']}');
  44. Navigator.of(context,rootNavigator: true).push(
  45. CupertinoPageRoute(
  46. builder: (context){
  47. return YSCourseDetail(orderStr: '${value['screct']}',);
  48. }
  49. )
  50. );
  51. },
  52. onReceiveMessage: (Map<String, dynamic> message) async {
  53. print("flutter onReceiveMessage: $message");
  54. },
  55. onReceiveNotificationAuthorization:(Map<String, dynamic> message) async {
  56. print("flutter onReceiveNotificationAuthorization: $message");
  57. });
  58. } on PlatformException {
  59. }
  60. super.initState();
  61. }
  62. final pageController = PageController();
  63. final List<Widget> widgets = [YSHome(), YSCourse(), YSSquare(), YSMine()];
  64. int currentIndex = 0;
  65. void onTap(int index) {
  66. if(index==3||index==2||index==1){
  67. isLogin(context,login: (){
  68. if(index==2){
  69. _isShow = false;
  70. }
  71. currentIndex = index;
  72. pageController.jumpToPage(index);
  73. });
  74. }else{
  75. if(index==2){
  76. _isShow = false;
  77. }
  78. currentIndex = index;
  79. pageController.jumpToPage(index);
  80. }
  81. }
  82. void onPageChanged(int index) {
  83. if(index==3||index==2||index==1){
  84. isLogin(context,login: (){
  85. currentIndex = index;
  86. setState(() {});
  87. });
  88. }else{
  89. currentIndex = index;
  90. setState(() {});
  91. }
  92. }
  93. @override
  94. Widget build(BuildContext context) {
  95. ScreenUtil.init(context,designSize: Size(750, 1624),allowFontScaling: false);
  96. return Scaffold(
  97. bottomNavigationBar: CupertinoTabBar(
  98. items: [
  99. BottomNavigationBarItem(
  100. icon: ImageIcon(AssetImage('lib/images/home.png'),size: 20,),
  101. label: '首页',
  102. ),
  103. BottomNavigationBarItem(
  104. icon: ImageIcon(AssetImage('lib/images/course.png'),size: 20,),
  105. label: '行程'
  106. ),
  107. BottomNavigationBarItem(
  108. icon: Stack(
  109. children: [
  110. ImageIcon(AssetImage('lib/images/square.png'),size: 20,),
  111. if(_isShow==true)Container(
  112. height: 10,
  113. width: 10,
  114. decoration: BoxDecoration(
  115. color: Colors.red,
  116. borderRadius: BorderRadius.all(Radius.circular(5))
  117. ),
  118. margin: EdgeInsets.only(left: 15),
  119. )
  120. ],
  121. ),//
  122. label: '广场'
  123. ),
  124. BottomNavigationBarItem(
  125. icon: ImageIcon(AssetImage('lib/images/mine.png'),size: 20,),
  126. label: '我的'
  127. ),
  128. ],
  129. currentIndex: currentIndex,
  130. onTap: onTap,
  131. activeColor: Color(0xFF007AFF),
  132. inactiveColor: Color(0xFF999999),
  133. ),
  134. body: NotificationListener<ShowNotification>(
  135. onNotification: (ShowNotification msg){
  136. onTap(1);
  137. return true;
  138. },
  139. child: PageView(
  140. controller: pageController,
  141. onPageChanged: onPageChanged,
  142. children: widgets,
  143. physics: NeverScrollableScrollPhysics(), // 禁止滑动
  144. ),
  145. ),
  146. );
  147. }
  148. }
  149. class ShowNotification extends Notification {
  150. bool isShow;
  151. ShowNotification(this.isShow);
  152. }