YSTabbar.dart 4.5 KB

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