| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import 'dart:async';
- import 'package:flutter/services.dart';
- class FlutterAliyunPush {
- static const MethodChannel _channel =
- const MethodChannel('aliyun_push');
- static bool registCallback = false;
- static Function onRegistSuccess;
- static Function onRegistError;
- static Future<String> get platformVersion async {
- final String version = await _channel.invokeMethod('getPlatformVersion');
- return version;
- }
- static Future<String> get initPush async {
- final String version = await _channel.invokeMethod('initPush');
- return version;
- }
- /**
- * 注册原生调用dart
- */
- static void registCallHandler() {
- if(registCallback) {
- return;
- }
- registCallback = true;
- _channel.setMethodCallHandler((call) {
- print("setMethodCallHandler:"+call.method);
- switch(call.method) {
- case "onPushRegistSuccess":
- if(onRegistSuccess != null) {
- onRegistSuccess(call.arguments);
- }
- break;
- case "onPushRegistError":
- if(onRegistError != null) {
- onRegistError(call.arguments);
- }
- break;
- }
- });
- }
- static void reigistOnRegistSuccess(Function callback) {
- onRegistSuccess = callback;
- registCallHandler();
- }
- static void reigistOnRegistError(Function callback) {
- onRegistError = callback;
- registCallHandler();
- }
- }
|