YSTabbar.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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: "5cdf5bc06073b6ba4b3eaf86", //你自己应用的 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. jpush.setup(
  59. appKey: "com.example.ysairplane2",
  60. channel: "developer-default",
  61. production: false,
  62. debug: true,
  63. );
  64. } on PlatformException {
  65. }
  66. super.initState();
  67. }
  68. final pageController = PageController();
  69. final List<Widget> widgets = [YSHome(), YSCourse(), YSSquare(), YSMine()];
  70. int currentIndex = 0;
  71. void onTap(int index) {
  72. if(index==3||index==2||index==1){
  73. isLogin(context,login: (){
  74. if(index==2){
  75. _isShow = false;
  76. }
  77. currentIndex = index;
  78. pageController.jumpToPage(index);
  79. });
  80. }else{
  81. if(index==2){
  82. _isShow = false;
  83. }
  84. currentIndex = index;
  85. pageController.jumpToPage(index);
  86. }
  87. }
  88. void onPageChanged(int index) {
  89. if(index==3||index==2||index==1){
  90. isLogin(context,login: (){
  91. currentIndex = index;
  92. setState(() {});
  93. });
  94. }else{
  95. currentIndex = index;
  96. setState(() {});
  97. }
  98. }
  99. @override
  100. Widget build(BuildContext context) {
  101. ScreenUtil.init(context,designSize: Size(750, 1624),allowFontScaling: false);
  102. return Scaffold(
  103. bottomNavigationBar: CupertinoTabBar(
  104. items: [
  105. BottomNavigationBarItem(
  106. icon: ImageIcon(AssetImage('lib/images/home.png'),size: 20,),
  107. label: '首页',
  108. ),
  109. BottomNavigationBarItem(
  110. icon: ImageIcon(AssetImage('lib/images/course.png'),size: 20,),
  111. label: '行程'
  112. ),
  113. BottomNavigationBarItem(
  114. icon: Stack(
  115. children: [
  116. ImageIcon(AssetImage('lib/images/square.png'),size: 20,),
  117. if(_isShow==true)Container(
  118. height: 10,
  119. width: 10,
  120. decoration: BoxDecoration(
  121. color: Colors.red,
  122. borderRadius: BorderRadius.all(Radius.circular(5))
  123. ),
  124. margin: EdgeInsets.only(left: 15),
  125. )
  126. ],
  127. ),//
  128. label: '广场'
  129. ),
  130. BottomNavigationBarItem(
  131. icon: ImageIcon(AssetImage('lib/images/mine.png'),size: 20,),
  132. label: '我的'
  133. ),
  134. ],
  135. currentIndex: currentIndex,
  136. onTap: onTap,
  137. activeColor: Color(0xFF007AFF),
  138. inactiveColor: Color(0xFF999999),
  139. ),
  140. body: NotificationListener<ShowNotification>(
  141. onNotification: (ShowNotification msg){
  142. onTap(1);
  143. return true;
  144. },
  145. child: PageView(
  146. controller: pageController,
  147. onPageChanged: onPageChanged,
  148. children: widgets,
  149. physics: NeverScrollableScrollPhysics(), // 禁止滑动
  150. ),
  151. ),
  152. );
  153. }
  154. }
  155. class ShowNotification extends Notification {
  156. bool isShow;
  157. ShowNotification(this.isShow);
  158. }