flutter与iOS交互flutter端通道封装
2020-07-29 本文已影响0人
Leo_L
flutter与iOS原生交互通道,flutter端通道书写简单封装。
代码:
/// channel 通道名称
/// method 方法名称
/// arguments 传递的参数
class ChannelPlugin {
final String channel;
final String method;
final dynamic arguments;
const ChannelPlugin({@required this.channel, @required this.method, this.arguments});
Future invokeMethod() async {
var result;
try {
result = await MethodChannel(this.channel).invokeMethod(this.method,this.arguments);
return Future.value(result);
} on PlatformException catch (e) {
return Future.error(e.toString());
}
}
}