当前位置:网站首页>Flutter学习5-集成-打包-发布
Flutter学习5-集成-打包-发布
2022-08-05 04:49:00 【hn_lgc】
官网地址: https://docs.flutter.dev/development/platform-integration
支持的平台
Android 4.1+ IOS 9+
主流浏览器 chrome edge 火狐 Safari
桌面端 windows linux mac
没有提到小程序,是这样说的,官方没有做保证运行的测试,有可能是第三方团队做的
目前最佳支持的平台是移动端和桌面端,web端还不是(2022.8)
平台通道-API互调,消息传递
Flutter通过消息传递的方式调用API允许您使用直接使用平台绑定的语言调用平台API,可称之为方法通道 平台通道 或者平台消息通道
名称:客户端,flutter部分,主机,平台,平台本地代码,平台绑定语言部分
应用程序的 Flutter 部分通过平台通道将消息发送到其host,即应用程序的非 Dart 部分。
host在平台通道上侦听并接收消息,然后它调用任意数量的特定于平台的 API ーー使用本地编程语言ーー并将响应发送回Flutter 部分(客户端)。
消息和响应是异步传递的,以确保用户界面保持响应。
注意:尽管Flutter以异步方式向Dart发送消息,但只要你调用一个通道方法
你必须在平台的主线程上调用该方法。
可以通过检查 defaultTargetPlatform 属性在 Flutter 应用程序中编写特定于平台的 Dart 代码。
平台通道数据类型支持和编解码器:
null
bool
int
int, if 32 bits not enough如果32位不够的话 java.lang.Long Java.lang Long
double 双倍
String 绳子
Uint8List byte[] 字节[]
Int32List int[] Int []
Int64List Int64列表
Float32List
Float64List
List 名单
Map 地图
注意 没有float
平台通道使用方法
import ‘package:flutter/services.dart’;
// 1 创建一个通道,传入的是通道名称,必须唯一
static const platform = MethodChannel(‘samples.flutter.dev/battery’);
// 2 然后,通过通道调用指定方法, 获取结果,注意是异步的,要用try catch包起来
final int result = await platform.invokeMethod(‘getBatteryLevel’);
// 3 平台上一样的创建方法通道(在平台上面配置好flutter引擎),设置同样的方法名字
// 4 然后监听调用的消息,
// 5 运行相关代码得到结果之后,通过回调接口对象回调即可
private val CHANNEL = “samples.flutter.dev/battery”
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
// This method is invoked on the main thread.
call, result ->
if (call.method == “getBatteryLevel”) {
val batteryLevel = getBatteryLevel()
if (batteryLevel != -1) {
result.success(batteryLevel)
} else {
result.error("UNAVAILABLE", "Battery level not available.", null)
}
} else {
result.notImplemented()
}
}
}
调用线程
通常,调用发起方必须是主线程或者主隔离区Isolate,被调用方可以是非主线程。
为了使通道的平台端处理程序在非主线程上执行,必须使用任务队列 API。目前只有 iOS 和 Android 支持这个特性。
将flutter添加到现有项目中
只需要几个步骤,你就可以将 Flutter 的生产力和表现力带到你自己的应用程序中。
Add-to-app 特性支持集成任意屏幕大小的多个实例。
Android Studio自动集成,最新版的没有找到按钮(2022.8)
只能手动集成
运行教程上的命令 成功 注意包名不能和原项目的包名相同 也就是下面项目名字改一下吧 加个Flutter
flutter create -t module --org com.公司名 项目名
settings.gradle添加命令,其中有一个binding标红,不用管
接着报一个莫名的错,什么重复了,Google搜索,更改dependencyResolutionManagement下面的
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
为
repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
就可以了
app依赖添加
implementation project(‘:flutter’)
问题处理:
1、一开始是没有设置Flutter SDK位置的, Android Studio会提示,或者手动设置
2、
这里可以看到flutter的架构还是比较灵活的,Flutter既可以作为一个单独的项目,也可以和原生项目结合起来用。两者都可以作为主项目,安装到手机上,然后调用另一方。(马甲包!??)
边栏推荐
猜你喜欢

雷克萨斯lm的安全性到底体现在哪里?一起来看看吧

flink读取mongodb数据源

多御安全浏览器 V10.8.3.1 版正式发布,优化多项内容

The production method of the powered small sailboat is simple, the production method of the electric small sailboat

write the story about us

mutillidae下载及安装

bytebuffer internal structure
![[MRCTF2020] Ezpop (detailed)](/img/19/920877ca36d1eda8d118637388ab05.png)
[MRCTF2020] Ezpop (detailed)

Detailed explanation of Mysql's undo log

【8.1】代码源 - 【第二大数字和】【石子游戏 III】【平衡二叉树】
随机推荐
大学物理---质点运动学
MySql index learning and use; (I think it is detailed enough)
The production method of the powered small sailboat is simple, the production method of the electric small sailboat
The log causes these pits in the thread block, you have to guard against
C language - vernacular to understand the original code, inverse code and complement code
【cesium】元素高亮显示
浅析主流跨端技术方案
4T硬盘剩余很多提示“No space left on device“磁盘空间不足
Redis哨兵模式配置文件详解
[informix] Resolving startup errors and solutions
【informix】解决启动报错大全,以及解决办法
Application status of digital twin technology in power system
Is the NPDP certificate high in gold content?Compared to PMP?
多御安全浏览器新版下载 | 功能优秀性能出众
Mysql的redo log详解
虚证、实证如何鉴别?
[极客大挑战 2019]FinalSQL
国学*周易*梅花易数 代码实现效果展示 - 梅花心易
Shell(4) Conditional Control Statement
[8.2] Code Source - [Currency System] [Coins] [New Year's Questions (Data Enhanced Edition)] [Three Stages]