YSTabbar.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:jpush_flutter/jpush_flutter.dart';
  5. import 'package:shared_preferences/shared_preferences.dart';
  6. class YSTabbar extends StatefulWidget {
  7. @override
  8. _YSPageState createState() => _YSPageState();
  9. }
  10. class _YSPageState extends State<YSTabbar> {
  11. int _selectedIndex = 0;
  12. final JPush jpush = new JPush();
  13. @override
  14. void initState() {
  15. Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
  16. _prefs.then((value) => {
  17. if(value.getInt('chapters')==null){
  18. value.setInt('chapters', 0),
  19. value.setInt('childId', 1),
  20. }
  21. });
  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. Navigator.of(context).push(
  42. CupertinoPageRoute(
  43. builder: (context){
  44. return null;
  45. }
  46. )
  47. );
  48. },
  49. onReceiveMessage: (Map<String, dynamic> message) async {
  50. print("flutter onReceiveMessage: $message");
  51. },
  52. onReceiveNotificationAuthorization:(Map<String, dynamic> message) async {
  53. print("flutter onReceiveNotificationAuthorization: $message");
  54. });
  55. } on PlatformException {
  56. }
  57. super.initState();
  58. }
  59. void onItemTap(int index){
  60. setState(() {
  61. _selectedIndex = index;
  62. });
  63. }
  64. @override
  65. Widget build(BuildContext context) {
  66. return CupertinoTabScaffold(
  67. tabBar: CupertinoTabBar(
  68. items: const<BottomNavigationBarItem>[
  69. BottomNavigationBarItem(
  70. icon: Icon(Icons.home),
  71. title: Text('首页')
  72. ),
  73. BottomNavigationBarItem(
  74. icon: Icon(Icons.calendar_today),
  75. title: Text('行程')
  76. ),
  77. BottomNavigationBarItem(
  78. icon: Icon(Icons.camera),
  79. title: Text('广场')
  80. ),
  81. BottomNavigationBarItem(
  82. icon: Icon(Icons.person),
  83. title: Text('我的')
  84. ),
  85. ],
  86. currentIndex: _selectedIndex,
  87. onTap: onItemTap,
  88. activeColor: Color(0xFF007AFF),
  89. inactiveColor: Color(0xFF999999),
  90. iconSize: 25,
  91. ),
  92. tabBuilder: (context,index){
  93. return CupertinoTabView(
  94. builder: (context){
  95. if (index == 0) {
  96. return null();
  97. }else if(index == 1){
  98. return null();
  99. }else{
  100. return null();
  101. }
  102. },
  103. );
  104. },
  105. );
  106. }
  107. }