当前位置:网站首页>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!??)
边栏推荐
猜你喜欢
随机推荐
JeeSite新建报表
Shell(4)条件控制语句
How to wrap markdown - md file
【8.4】代码源 - 【数学】【历法】【删库】【不朴素的数列(Bonus)】
七夕节赚徽章拉
overloaded operator
Qixi Festival earn badges
There are a lot of 4T hard drives remaining, prompting "No space left on device" insufficient disk space
The log causes these pits in the thread block, you have to guard against
一篇博客通关Redis技术栈
[MRCTF2020]Ezpop(详解)
不看后悔,appium自动化环境完美搭建
【测量学】速成汇总——摘录高数帮
Bytebuffer put flip compact clear method demonstration
flink读取mongodb数据源
App快速开发建设心得:小程序+自定义插件的重要性
Please write the SparkSQL statement
Why did you start preparing for the soft exam just after the PMP exam?
A 35-year-old software testing engineer with a monthly salary of less than 2W, resigns and is afraid of not finding a job, what should he do?
creo怎么测量点到面的距离