flutter_push_method_channel.dart
1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'flutter_push_platform_interface.dart';
import 'mix_push_plugin_listener.dart';
/// An implementation of [FlutterPushPlatform] that uses method channels.
class MethodChannelFlutterPush extends FlutterPushPlatform {
/// The method channel used to interact with the native platform.
@visibleForTesting
final methodChannel = const MethodChannel('ewin:flutter_push');
XiaoMiPushPluginListener? listener;
@override
Future<String?> getPlatformVersion() async {
final version =
await methodChannel.invokeMethod<String>('getPlatformVersion');
return version;
}
/// 初始化,如果没有appId或appKey,请登录小米开发者中心申请
/// [appId] 应用appId
/// [appKey] 应用appKey
Future<void> init({
String? defaultPlatform,
String? appId,
String? appKey,
}) async {
return await methodChannel.invokeMethod('init', {
"defaultPlatform":defaultPlatform,
"appId": appId,
"appKey": appKey,
});
}
Future<bool> checkPermission() async {
return await methodChannel.invokeMethod('checkPermission');
}
Future<bool> getPermission() async {
return await methodChannel.invokeMethod('getPermission');
}
/// 添加消息监听
void addListener(ListenerValue func) {
listener ??= XiaoMiPushPluginListener(methodChannel);
listener!.addListener(func);
}
/// 移除消息监听
void removeListener(ListenerValue func) {
listener ??= XiaoMiPushPluginListener(methodChannel);
listener!.removeListener(func);
}
/// 获取客户端的 RegId
Future<String?> getRegId() async {
return await methodChannel.invokeMethod('getRegId');
}
/// 获取客户端的 RegId
Future<String?> msgReceive() async {
return await methodChannel.invokeMethod('msgReceive');
}
}