jgpush_service.dart 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import 'package:flutter/material.dart';
  2. import 'package:jpush_flutter/jpush_flutter.dart';
  3. import 'package:lszlgl/base/base_lifecycle_state.dart';
  4. import 'package:lszlgl/config/app_config.dart';
  5. import 'package:lszlgl/config/colors.dart';
  6. import 'package:lszlgl/main.dart';
  7. class JGPushService{
  8. static final JPush jPush = JPush();
  9. static Future<void> jgInit(AppEnvironment env) async{
  10. jPush.setup(
  11. // 极光推送 正式环境appkey需要再申请
  12. appKey: env == AppEnvironment.product ? '336425aac947172a06b70cbb' : '2f42e3db4d0083b0bc5a3f6c',
  13. channel: 'developer-default',
  14. production: env == AppEnvironment.product ? true : false,
  15. debug: env == AppEnvironment.develop ? true : false
  16. );
  17. jPush.addEventHandler(
  18. // 接收通知回调方法。
  19. onReceiveNotification: (Map<String, dynamic> message) async {
  20. logger.d("极光消息:onReceiveNotification: $message");
  21. },
  22. // 点击通知回调方法。
  23. onOpenNotification: (Map<String, dynamic> message) async {
  24. // print("flutter onOpenNotification: $message");
  25. logger.d('极光消息:$message');
  26. MyNavigator.showDialog(
  27. tag: 'jsPop',
  28. builder: (ctx){
  29. return AlertDialog(
  30. titlePadding: const EdgeInsets.fromLTRB(8, 26, 8, 4),
  31. actionsPadding:const EdgeInsets.symmetric(horizontal: 8.0,vertical: 4),
  32. actionsAlignment: MainAxisAlignment.spaceAround,
  33. shape: RoundedRectangleBorder(
  34. borderRadius: BorderRadius.circular(12.0),
  35. ),
  36. title: Text(message['title'] ,textAlign: TextAlign.center,style: const TextStyle(fontWeight: FontWeight.bold),),
  37. content: Text(message['alert'],),
  38. actions: <Widget>[
  39. TextButton(
  40. child: const Text('知道了',style: TextStyle(color: MyColor.c_28A3ED,fontWeight: FontWeight.bold),),
  41. onPressed: () {
  42. MyNavigator.dismiss(tag: 'jsPop');
  43. },
  44. ),
  45. ],
  46. );
  47. },);
  48. },
  49. // 接收自定义消息回调方法。
  50. onReceiveMessage: (Map<String, dynamic> message) async {
  51. logger.d("极光消息: onReceiveMessage: $message");
  52. },
  53. );
  54. }
  55. }