Flutter ——> Native
1.Flutter和Native定义一个相同的字符串CHANNEL_NAME
Flutter 端代码:
2、static const MethodChannel methodChannel = MethodChannel(CHANNEL_NAME);
3、final String result = await methodChannel.invokeMethod(nativeMethod, args);
Native 端代码:
4、 val channel = new MethodChannel((FlutterView)flutterView, CHANNEL_NAME)
5、
channel.setMethodCallHandler { call, result ->
//call.method 来获取方法名
//call.arguments 来获取入参
//result.success来放回成功处理结果
//result.error来放回失败后的结果
//result.notImplemented来放回为实现该方法
}
Native ——> Flutter
在( Flutter ——> Native)代码基础上面
Native 端代码:
1、
channel.invokeMethod(flutterMethod, args, new MethodChannel.Result () {
@Override
public void success(@Nullable Object o) {
}
@Override
public void error(String s, @Nullable String s1, @Nullable Object o) {
}
@Override
public void notImplemented() {
}
});
Flutter端
2、
_channel.setMethodCallHandler((MethodCall call) {
//call.method 来获取方法名
//call.arguments 来获取入参
});
网友评论