赞
踩
Flutter与原生的交互主要通过MethodChannel的方式
本文只列举两种形式的插件,掌握基础的插件写法,举一反三,例如我github项目中的高德定位,6.0以上权限申请等,还需要掌握iOS的的基础语言o c,swift才能编写iOS插件。
效果GIF
Channel.gif
从Flutter界面跳转到原生,且带参数
1. 实现插件
public class FlutterPluginJumpToAct implements MethodChannel.MethodCallHandler {
public static String CHANNEL = "com.jzhu.jump/plugin";
static MethodChannel channel;
private Activity activity;
private FlutterPluginJumpToAct(Activity activity) {
this.activity = activity;
}
public static void registerWith(PluginRegistry.Registrar registrar) {
channel = new MethodChannel(registrar.messenger(), CHANNEL);
FlutterPluginJumpToAct instance = new FlutterPluginJumpToAct(registrar.activity());
//setMethodCallHandler在此通道上接收方法调用的回调
channel.setMethodCallHandler(instance);
}
@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
//通过MethodCall可以获取参数和方法名,然后再寻找对应的平台业务,本案例做了2个跳转的业务
//接收来自flutter的指令oneAct
if (call.method.equals("oneAct")) {
//跳转到指定Activity
Intent intent = new Intent(activity, OneActivity.class);
act
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。