当前位置:网站首页>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!??)
边栏推荐
猜你喜欢

Analyses the mainstream across technology solutions

多列属性column元素的可见性:display、visibility、opacity、垂直对齐方式:vertical-align、z-index 越大越显示在上层

机器学习概述

C+ +核心编程
![[MRCTF2020] PYWebsite](/img/d4/57e8e5ee45b742894679f3f5671516.png)
[MRCTF2020] PYWebsite

The production method of the powered small sailboat is simple, the production method of the electric small sailboat
![[BSidesCF 2019] Kookie](/img/29/19e7c244feb86b37ab32a53aa11f25.png)
[BSidesCF 2019] Kookie
![[极客大挑战 2019]FinalSQL](/img/e4/0c8225ef7c5e7e5bdbaac2ef6fc867.png)
[极客大挑战 2019]FinalSQL

概率论的学习和整理8: 几何分布和超几何分布

【cesium】加载并定位 3D Tileset
随机推荐
C language - vernacular to understand the original code, inverse code and complement code
[8.2] Code Source - [Currency System] [Coins] [New Year's Questions (Data Enhanced Edition)] [Three Stages]
how to measure distance from point to face in creo
About the installation of sklearn library
mutillidae download and installation
In the hot summer, teach you to use Xiaomi smart home accessories + Raspberry Pi 4 to connect to Apple HomeKit
[SWPU2019]Web1
[CISCN2019 South China Division]Web11
u-boot中的u-boot,dm-pre-reloc
【8.1】代码源 - 【第二大数字和】【石子游戏 III】【平衡二叉树】
大学物理---质点运动学
How to deal with DNS hijacking?
人性的弱点
How to wrap markdown - md file
Learning and finishing of probability theory 8: Geometric and hypergeometric distributions
Day019 Method overriding and introduction of related classes
Application status of digital twin technology in power system
LeetCode:1403. 非递增顺序的最小子序列【贪心】
算法---一和零(Kotlin)
[MRCTF2020] Ezpop (detailed)