当前位置:网站首页>Flutter learning 5-integration-packaging-publish
Flutter learning 5-integration-packaging-publish
2022-08-05 04:50:00 【hn_lgc】
Official website address: https://docs.flutter.dev/development/platform-integration
Supported Platforms
Android 4.1+ IOS 9+
Mainstream browsers chrome edge Firefox Safari
Desktop windows linux mac
There is no mention of the applet, that is to say, the official did not do the test to guarantee the operation, there isIt may be done by a third-party team
Currently the best supported platforms are mobile and desktop, web is not yet (2022.8)
Platform Channel-API Intermodulation, Messaging
Flutter calls APIs by means of message passing, allowing you to call platform APIs directly using the language bound to the platform, which can be called method channel platform channel or platform message channel
Name:client, flutter section, host, platform, platform native code, platform binding language section
The Flutter part of the application sends messages through the platform channel to its host, the non-Dart part of the application.The
host listens on the platform channel and receives messages, then it calls any number of platform-specific APIs — in a native programming language — and sends responses back to the Flutter part (the client).
Messages and responses are delivered asynchronously to ensure that the user interface remains responsive.
Note: Although Flutter sends messages to Dart asynchronously, whenever you call a channel method
you must call that method on the platform's main thread.
Platform-specific Dart code can be written in Flutter applications by checking the defaultTargetPlatform property.
Platform channel data type support and codecs:
null
bool
int
int, if 32 bits not enough java.lang.Long Java.lang Long
double double
String string
Uint8List byte[] byte[]
Int32List int[] Int []
Int64List Int64 List
Float32List
Float64List
List List
Map Map
Note no float
How to use the platform channel
import 'package:flutter/services.dart';
// 1 Create a channel, pass in the channel name, which must be unique
static const platform = MethodChannel('samples.flutter.dev/battery');
// 2 Then, call the specified method through the channel, get the result, note that it is asynchronous, wrap it with try catch
final int result = await platform.invokeMethod('getBatteryLevel');
// 3 Create the same method channel on the platform (configure the flutter engine on the platform), set the same method name
// 4 Then monitor the call message,
// 5 After running the relevant code to get the result, you can call back through the callback interface object
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()}}}Calling thread
Usually, the call originator must be the main thread or the main isolation area Isolate, and the callee can be a non-main thread.
In order for a channel's platform-side handler to execute on a non-main thread, the task queue API must be used.Currently only iOS and Android support this feature.
Add flutter to an existing project
In just a few steps, you can bring the productivity and expressiveness of Flutter to your own applications.
The Add-to-app feature supports the integration of multiple instances of any screen size.
Android Studio is automatically integrated, the latest version does not find the button (2022.8)
Only manual integration
Run the command on the tutorial successfully. Note that the package name cannot be the same as the original project package name, that is, the following project name is changedLet's add a Flutter
flutter create -t module --org com. company name project name
settings.gradle add command, there is a binding marked red, don't care
Then report an inexplicable error, what is repeated, Google search, change
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
under dependencyResolutionManagement to
repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
That's it
App dependency add
implementation project(':flutter')
Problem handling:
1. The Flutter SDK location is not set at the beginning, Android Studio will prompt, or set it manually
2.
Here you can see that the architecture of flutter is relatively flexible. Flutter can be used as a separate project or combined with native projects.Both can be used as the main project, installed on the phone, and then called into the other.(Vest bag!??)
边栏推荐
猜你喜欢

upload上传图片到腾讯云,如何上传图片

flink读取mongodb数据源

35岁的软件测试工程师,月薪不足2W,辞职又怕找不到工作,该何去何从?

Flutter学习5-集成-打包-发布

将故事写成我们
![[BSidesCF 2019] Kookie](/img/29/19e7c244feb86b37ab32a53aa11f25.png)
[BSidesCF 2019] Kookie

Detailed explanation of each module of ansible

Homework 8.4 Interprocess Communication Pipes and Signals

Day019 Method overriding and introduction of related classes

How to solve complex distribution and ledger problems?
随机推荐
Flutter学习4-基本UI组件
dedecms织梦tag标签不支持大写字母修复
机器学习概述
LeetCode:1403. 非递增顺序的最小子序列【贪心】
雷克萨斯lm的安全性到底体现在哪里?一起来看看吧
C++ core programming
How to identify false evidence and evidence?
[极客大挑战 2019]FinalSQL
动力小帆船制作方法简单,电动小帆船制作方法
Analyses the mainstream across technology solutions
upload upload pictures to Tencent cloud, how to upload pictures
Cron(Crontab)--use/tutorial/example
人性的弱点
mysql数据库表什么字段类型的存储长度最大?
Mvi架构浅析
特征预处理
4T硬盘剩余很多提示“No space left on device“磁盘空间不足
【 8.4 】 source code - [math] [calendar] [delete library 】 【 is not a simple sequence (Bonus) 】
Error creating bean with name ‘configDataContextRefresher‘ defined in class path resource
淘宝账号如何快速提升到更高等级