YSPage.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutterappfuyou/code/YSInformation.dart';
  5. import 'package:flutterappfuyou/code/live/YSLive.dart';
  6. import 'package:flutterappfuyou/code/version3/YSCoupon.dart';
  7. import 'package:jpush_flutter/jpush_flutter.dart';
  8. import 'package:shared_preferences/shared_preferences.dart';
  9. import 'code/YSHome.dart';
  10. import 'code/YSMine.dart';
  11. import 'code/YSNote.dart';
  12. import 'code/base/YSTools.dart';
  13. import 'code/version3/view/YSCouponCardView.dart';
  14. class YSPage extends StatefulWidget {
  15. @override
  16. _YSPageState createState() => _YSPageState();
  17. }
  18. class _YSPageState extends State<YSPage> {
  19. int _selectedIndex = 0;
  20. int _refresh = 1;
  21. final JPush jpush = new JPush();
  22. @override
  23. void initState() {
  24. super.initState();
  25. setupLicense();
  26. Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
  27. _prefs.then((value) => {
  28. if(value.getInt('chapters')==null){
  29. value.setInt('chapters', 0),
  30. value.setInt('childId', 1),
  31. }
  32. });
  33. jpush.setup(
  34. appKey: "5cdf5bc06073b6ba4b3eaf86", //你自己应用的 AppKey
  35. channel: "theChannel",
  36. production: false,
  37. debug: true,
  38. );
  39. jpush.applyPushAuthority(
  40. new NotificationSettingsIOS(sound: true, alert: true, badge: true)
  41. );
  42. jpush.getRegistrationID().then((rid) {
  43. print("flutter get registration id : $rid");
  44. });
  45. try {
  46. jpush.addEventHandler(
  47. onReceiveNotification: (Map<String, dynamic> message) async {
  48. print("flutter onReceiveNotification: $message");
  49. },
  50. onOpenNotification: (Map<String, dynamic> message) async {
  51. print("flutter onOpenNotification: $message");
  52. Navigator.of(context).push(
  53. CupertinoPageRoute(
  54. builder: (context){
  55. return YSInformation();
  56. }
  57. )
  58. );
  59. },
  60. onReceiveMessage: (Map<String, dynamic> message) async {
  61. print("flutter onReceiveMessage: $message");
  62. },
  63. onReceiveNotificationAuthorization:(Map<String, dynamic> message) async {
  64. print("flutter onReceiveNotificationAuthorization: $message");
  65. });
  66. } on PlatformException {
  67. }
  68. }
  69. void onItemTap(int index){
  70. setState(() {
  71. if(index==2){
  72. _refresh++;
  73. }
  74. _selectedIndex = index;
  75. });
  76. }
  77. @override
  78. Widget build(BuildContext context) {
  79. return NotificationListener<CustomerValueNotification>(
  80. onNotification: (value){
  81. Map map = value.value;
  82. Map item = map['item'];
  83. List array = map['array'];
  84. ysShowBottomAlertView(context, YSCodeAlertView(array: array,item: item,),isBarr: true);
  85. return true;
  86. },
  87. child: CupertinoTabScaffold(
  88. tabBar: CupertinoTabBar(
  89. items: <BottomNavigationBarItem>[
  90. BottomNavigationBarItem(
  91. icon: Icon(Icons.home),
  92. label: '首页'
  93. ),
  94. BottomNavigationBarItem(
  95. icon: Icon(Icons.live_tv),
  96. label: '直播'
  97. ),
  98. BottomNavigationBarItem(
  99. icon: Image.asset('lib/images/${_selectedIndex==2?'fy_yhj':'暂停'}.png',height: 20,width: 20,),
  100. label: '两筛'
  101. ),
  102. BottomNavigationBarItem(
  103. icon: Icon(Icons.supervised_user_circle),
  104. label: '我的'
  105. ),
  106. ],
  107. currentIndex: _selectedIndex,
  108. onTap: onItemTap,
  109. activeColor: Color(0xFFDB5278),
  110. inactiveColor: Color(0xFFBCBCBC),
  111. iconSize: 25,
  112. border: Border(top: BorderSide(color: Colors.grey,width: 0.2)),
  113. ),
  114. tabBuilder: (context,index){
  115. return CupertinoTabView(
  116. builder: (context){
  117. if (index == 0) {
  118. return YSHome();
  119. }else if(index == 1){
  120. return YSLive();
  121. }else if(index == 2){
  122. return YSCoupon(key: Key('${_refresh}YS'),);
  123. }else{
  124. return YSMine();
  125. }
  126. },
  127. );
  128. },
  129. ),
  130. );
  131. }
  132. }