当前位置:网站首页>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!??)
边栏推荐
- [Surveying] Quick Summary - Excerpt from Gaoshu Gang
- 七夕节赚徽章拉
- 将故事写成我们
- 【无标题】
- What is the function of industrial-grade remote wireless transmission device?
- dedecms error The each() function is deprecated
- University Physics---Particle Kinematics
- 淘宝账号如何快速提升到更高等级
- u-boot中的u-boot,dm-pre-reloc
- Visibility of multi-column attribute column elements: display, visibility, opacity, vertical alignment: vertical-align, z-index The larger it is, the more it will be displayed on the upper layer
猜你喜欢
LeetCode:1403. 非递增顺序的最小子序列【贪心】
小程序_动态设置tabBar主题皮肤
Error creating bean with name ‘configDataContextRefresher‘ defined in class path resource
【 8.4 】 source code - [math] [calendar] [delete library 】 【 is not a simple sequence (Bonus) 】
AUTOCAD - dimension association
Flutter学习5-集成-打包-发布
狗仔队:表面编辑多视点图像处理
In the hot summer, teach you to use Xiaomi smart home accessories + Raspberry Pi 4 to connect to Apple HomeKit
请写出SparkSQL语句
Paparazzi: Surface Editing by way of Multi-View Image Processing
随机推荐
Some conventional routines of program development (1)
What is ASEMI photovoltaic diode, the role of photovoltaic diode
u-boot中的u-boot,dm-pre-reloc
Detailed explanation of each module of ansible
服务器磁盘阵列
There are a lot of 4T hard drives remaining, prompting "No space left on device" insufficient disk space
[8.2] Code Source - [Currency System] [Coins] [New Year's Questions (Data Enhanced Edition)] [Three Stages]
Error creating bean with name ‘configDataContextRefresher‘ defined in class path resource
[Geek Challenge 2019]FinalSQL
C+ +核心编程
【学生毕业设计】基于web学生信息管理系统网站的设计与实现(13个页面)
Mysql的undo log详解
Day019 Method overriding and introduction of related classes
ansible各个模块详解
二叉树基本性质+oj题解析
Flutter学习三-Flutter基本结构和原理
JeeSite New Report
【背包九讲——01背包问题】
[BSidesCF 2019]Kookie
淘宝账号如何快速提升到更高等级