当前位置:网站首页>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!??)
边栏推荐
- App rapid development and construction experience: the importance of small programs + custom plug-ins
- The log causes these pits in the thread block, you have to guard against
- 【无标题】
- 8.04 Day35-----MVC three-tier architecture
- Paparazzi: Surface Editing by way of Multi-View Image Processing
- [8.2] Code Source - [Currency System] [Coins] [New Year's Questions (Data Enhanced Edition)] [Three Stages]
- [SWPU2019]Web1
- 什么是ASEMI光伏二极管,光伏二极管的作用
- [CISCN2019 South China Division]Web11
- 【8.4】代码源 - 【数学】【历法】【删库】【不朴素的数列(Bonus)】
猜你喜欢
随机推荐
工业级远距离无线传输装置的功能有哪些?
Please write the SparkSQL statement
What is the function of industrial-grade remote wireless transmission device?
upload upload pictures to Tencent cloud, how to upload pictures
Why did you start preparing for the soft exam just after the PMP exam?
【8.1】代码源 - 【第二大数字和】【石子游戏 III】【平衡二叉树】
Redis哨兵模式配置文件详解
浅析主流跨端技术方案
【无标题】
Analyses the mainstream across technology solutions
flink读取mongodb数据源
DNS被劫持如何处理?
[informix] Resolving startup errors and solutions
说说数据治理中常见的20个问题
How to deal with DNS hijacking?
1007 Climb Stairs (贪心 | C思维)
write the story about us
动力小帆船制作方法简单,电动小帆船制作方法
How to wrap markdown - md file
LeetCode:1403. 非递增顺序的最小子序列【贪心】


![[BJDCTF2020] EasySearch](/img/60/464de3bcdda876171b9f61ad31bff1.png)



![[Geek Challenge 2019]FinalSQL](/img/e4/0c8225ef7c5e7e5bdbaac2ef6fc867.png)


