一、flutter提供的FlutterMethodChanel与原生(ios&android)进行交换
flutter与原生交互图:
ios注册flutter调用通道
//oc 注册flutter通信频道,方便flutter调用FlutterMethodChannel* batteryChannel = [FlutterMethodChannelmethodChannelWithName:@"samples.flutter.dev/battery"binaryMessenger:self.binaryMessenger];__weak typeof(self) weakSelf = self;[batteryChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {// Note: this method is invoked on the UI thread.NSLog(@"flutter call: %@ %@",call.method,call.arguments);if([@"jimi" isEqualToString:call.method]){NSDictionary* dic = call.arguments;NSMutableDictionary* param = [BHB2cSingel getBaohongHeader];NSMutableString* data = [BHB2cSingel getBaohongHeaderParam:dic];result(@{@"code":@(200),@"token":[[BHUserCenter defaultCenter] token] ? [[BHUserCenter defaultCenter] token] : @"" ,@"data":data,@"header":param,});}}];
flutter 调用原生通道
static const platform = const MethodChannel('samples.flutter.dev/battery');
static Future<Map> jimi(Map param) async {String batteryLevel;try {//等待返回结果// final int result = await platform.invokeMethod('jimi',{"buque":"时间分开了"}).then((value) {// print(value);//// });Map res = await platform.invokeMethod('jimi',param == null ? {} : param);print(res);return res;} on PlatformException catch (e) {batteryLevel = "Failed to get battery level: '${e.message}'.";}}
二、App与b2c交换关系图
三、b2c依赖原生接口,原生必须实现一下接口
接口名 功能
jimi. 获取token, 获取头信息,对参数进行加密
isHiddeTabbar 隐藏原生底部导航菜单
pay. 调用支付功能,支付宝,微信
back. 原生返回上一个界面
share 调用原生分享功能
openWeb 原生打开一个h5界面