flutter 调用原生安卓插件_GitHub - llayjun/flutter_to_native: flutter通过两种方式调用原生的方法(1,本地android目录,2,plugin的导入)...

flutter_app

A new Flutter application.

Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our

online documentation, which offers tutorials,

samples, guidance on mobile development, and a full API reference.

flutter调用原生安卓的方法

这边通过两种方式

在flutter项目中的android目录进行编写原生代码

导入的plugin中的android目录中进行编写原生代码

第一种方式

首先创建FlutterAppPlugin文件,CHANNEL和flutter中lib中的相互对应,用于建立联系

FlutterAppPlugin中的方法与flutter中lib中相互对应

MainActivity继承FlutterActivity,注册

FlutterAppPlugin.registerWith(this.flutterEngine)

调用的话就看代码了

第二种方式

首先新建一个plugin,在pubspec.yaml中引入,地址一定要正确

live_plugin:

path: plugin\live_plugin

通过上面的pub get会在flutter项目中的GeneratedPluginRegistrant类中自动生成

flutterEngine.getPlugins().add(new com.llayjun.live_plugin.LivePlugin());

同上面的3,不过是注册

// 注册plugin

GeneratedPluginRegistrant.registerWith(this.flutterEngine!!)

调用的话就看代码了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值