-
Notifications
You must be signed in to change notification settings - Fork 4
/
moblink_interface.dart
83 lines (63 loc) · 2.04 KB
/
moblink_interface.dart
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:moblink/moblink_defines.dart';
class Moblink {
static const MethodChannel _channel =
const MethodChannel('com.yoozoo.mob/moblink');
static const EventChannel java_to_flutter = const EventChannel("JAVA_TO_FLUTTER");
static Future<dynamic> listenNativeEvent() {
print("QQQ 我执行了");
java_to_flutter.receiveBroadcastStream().listen(_onEvent, onError:_onError);
print("QQQ 我执行完了");
}
static Future<dynamic> _onEvent(Object event) {
print("QQQ _onEvent");
print("onEvent: $event ");
}
static Future<dynamic> _onError(Object error) {
print("QQQ _onError");
print(error);
}
static Future<dynamic> getMobId(MLSDKScene scene,
Function(String mobid, String domain, MLSDKError error) result) {
Map args = {"path": scene.path, "params": scene.params};
Future<dynamic> callback =
_channel.invokeMethod(MobLinkMethods.getMobId.name, args);
callback.then((dynamic response) {
if (result != null) {
result(response["mobid"], response["domain"],
MLSDKError(rawData: response["error"]));
}
});
return callback;
}
static Future<dynamic> restoreScene(Function(MLSDKScene scene) result) {
Future<dynamic> callback =
_channel.invokeMethod(MobLinkMethods.restoreScene.name);
callback.then((dynamic response) {
if (result != null) {
MLSDKScene scenes =
new MLSDKScene(response["path"], response["params"]);
scenes.mobid = response["mobid"];
scenes.className = response["className"];
scenes.rawURL = response["rawURL"];
result(scenes);
}
});
return callback;
}
}
class MLSDKScene {
// path (required)
String path;
// custom parameter (Optional)
Map params;
// mobid(Readonly)
String mobid;
// class name of the corresponding path(Readonly)
String className;
// original link(Readonly)
String rawURL;
// create scene
MLSDKScene(this.path, this.params);
}