send method
发送发送指定信息到某一个方法中。
Implementation
Future<Map<String, dynamic>?> send(
{required String methodName,
Map<String, dynamic>? params}) {
Map<String, dynamic>? params0 = params ?? {};
String json = jsonEncode(_wrap(code: "0", data: params0));
return _methodChannel
.invokeMethod<String>(methodName, json)
.then((String? value) {
if (value == null) {
return Future.value(_wrap(invoke: false));
}
try {
Map<String, dynamic> result = jsonDecode(value);
return Future.value(result["data"]);
} on PlatformException catch (e) {
debugPrint("KooChannel <${e.toString()}>");
return Future.value(_wrap(
code: e.code,
msg: e.message ?? "",
data: {"error": e.details},
invoke: false));
} on MissingPluginException catch (e) {
debugPrint("KooChannel <${e.toString()}>");
return Future.value(_wrap(
code: "-998",
msg: e.message ?? "",
data: {"error": e.toString()},
invoke: false));
}
}
);
}