12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import 'package:flutter/material.dart';
- import 'package:jpush_flutter/jpush_flutter.dart';
- import 'package:lszlgl/base/base_lifecycle_state.dart';
- import 'package:lszlgl/config/app_config.dart';
- import 'package:lszlgl/config/colors.dart';
- import 'package:lszlgl/main.dart';
- class JGPushService{
- static final JPush jPush = JPush();
- static Future<void> jgInit(AppEnvironment env) async{
- jPush.setup(
- // 极光推送 正式环境appkey需要再申请
- appKey: env == AppEnvironment.product ? '336425aac947172a06b70cbb' : '2f42e3db4d0083b0bc5a3f6c',
- channel: 'developer-default',
- production: env == AppEnvironment.product ? true : false,
- debug: env == AppEnvironment.develop ? true : false
- );
- jPush.addEventHandler(
- // 接收通知回调方法。
- onReceiveNotification: (Map<String, dynamic> message) async {
- logger.d("极光消息:onReceiveNotification: $message");
- },
- // 点击通知回调方法。
- onOpenNotification: (Map<String, dynamic> message) async {
- // print("flutter onOpenNotification: $message");
- logger.d('极光消息:$message');
- MyNavigator.showDialog(
- tag: 'jsPop',
- builder: (ctx){
- return AlertDialog(
- titlePadding: const EdgeInsets.fromLTRB(8, 26, 8, 4),
- actionsPadding:const EdgeInsets.symmetric(horizontal: 8.0,vertical: 4),
- actionsAlignment: MainAxisAlignment.spaceAround,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(12.0),
- ),
- title: Text(message['title'] ,textAlign: TextAlign.center,style: const TextStyle(fontWeight: FontWeight.bold),),
- content: Text(message['alert'],),
- actions: <Widget>[
- TextButton(
- child: const Text('知道了',style: TextStyle(color: MyColor.c_28A3ED,fontWeight: FontWeight.bold),),
- onPressed: () {
- MyNavigator.dismiss(tag: 'jsPop');
- },
- ),
- ],
- );
- },);
- },
- // 接收自定义消息回调方法。
- onReceiveMessage: (Map<String, dynamic> message) async {
- logger.d("极光消息: onReceiveMessage: $message");
- },
- );
- }
- }
|