Build Linux apps with Flutter
This page discusses considerations unique to building Linux apps with Flutter, including shell integration and preparation of apps for distribution.
Integrate with Linux
#The Linux programming interface,
comprising library functions and system calls,
is designed around the C language and ABI.
Fortunately, Dart provides the dart:ffi
package,
which enables Dart programs to call into C libraries.
Foreign Function Interfaces (FFI) allow Flutter apps to perform the following with native libraries:
- allocate native memory with
malloc
orcalloc
- support pointers, structs, and callbacks
- support Application Binary Interface (ABI) types like
long
andsize_t
To learn more about calling C libraries from Flutter,
consult C interop using dart:ffi
.
Many apps benefit from using a package that wraps the underlying library calls in a more convenient, idiomatic Dart API. Canonical has built a series of packages with a focus on enabling Dart and Flutter on Linux, including support for desktop notifications, dbus, network management, and Bluetooth.
In general, many other packages support creating Linux apps,
including common packages such as url_launcher
,
shared_preferences
, file_selector
, and path_provider
.
Prepare Linux apps for distribution
#The executable binary can be found in your project under
build/linux/x64/<build mode>/bundle/
.
Alongside your executable binary in the bundle
directory,
you can find two directories:
lib
contains the required.so
library filesdata
contains the application's data assets, such as fonts or images
In addition to these files, your application also relies on various
operating system libraries against which it's been compiled.
To see the full list of libraries,
use the ldd
command on your application's directory.
For example, assume you have a Flutter desktop application
called linux_desktop_test
.
To inspect the its system library dependencies, use the following commands:
flutter build linux --release
ldd build/linux/x64/release/bundle/linux_desktop_test
To wrap up this application for distribution,
include everything in the bundle
directory
and verify the target Linux system has all required system libraries.
This might only require using the following command.
sudo apt-get install libgtk-3-0 libblkid1 liblzma5
To learn how to publish a Linux application to the Snap Store, consult Build and release a Linux application to the Snap Store.
Additional resources
#除非另有说明,本文档之所提及适用于 Flutter 的最新稳定版本,本页面最后更新时间: 2024-05-30。 查看文档源码 或者 为本页面内容提出建议。