flutter-setting-up-on-linux
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSetting Up a Linux Environment for Flutter Development
为Flutter开发搭建Linux环境
Contents
目录
System Dependencies
系统依赖
To build and run Flutter applications on a Linux desktop, install the required C/C++ toolchain and system libraries. Flutter relies on to interface with Linux system calls and the GTK framework for UI rendering.
dart:ffiRequired packages for Debian/Ubuntu-based distributions:
- Core Utilities: ,
curl,git,unzip,xz-utilszip - Build Tools: ,
clang,cmake,ninja-buildpkg-config - Libraries: ,
libglu1-mesa,libgtk-3-devlibstdc++-12-dev
要在Linux桌面端构建和运行Flutter应用程序,需要安装必要的C/C++工具链和系统库。Flutter依赖与Linux系统调用交互,并依赖GTK框架进行UI渲染。
dart:ffi基于Debian/Ubuntu的发行版所需软件包:
- 核心工具: ,
curl,git,unzip,xz-utilszip - 构建工具: ,
clang,cmake,ninja-buildpkg-config - 库文件: ,
libglu1-mesa,libgtk-3-devlibstdc++-12-dev
Workflow: Configuring the Linux Toolchain
工作流:配置Linux工具链
Follow this sequential workflow to prepare the Linux host for Flutter desktop development.
Task Progress:
- 1. Update package lists and upgrade existing packages.
- 2. Install core utilities and build dependencies.
- 3. Configure IDE/Editor with Flutter support.
- 4. (Conditional) Enable Linux support on ChromeOS.
1. Update and Install Dependencies
Execute the following command to install all required packages on Debian/Ubuntu systems:
bash
sudo apt-get update -y && sudo apt-get upgrade -y
sudo apt-get install -y curl git unzip xz-utils zip libglu1-mesa clang cmake ninja-build pkg-config libgtk-3-dev libstdc++-12-dev2. Conditional: ChromeOS Setup
- If developing on a Chromebook: Turn on Linux support in the ChromeOS settings. Ensure the Linux container is fully updated using the commands above before proceeding.
apt-get
3. IDE Configuration
Install Visual Studio Code, Android Studio, or an IntelliJ-based IDE. Install the official Dart and Flutter extensions/plugins to enable language server features and debugging capabilities.
按照以下顺序工作流准备Linux主机以进行Flutter桌面开发。
任务进度:
- 1. 更新软件包列表并升级现有软件包。
- 2. 安装核心工具和构建依赖。
- 3. 为IDE/编辑器配置Flutter支持。
- 4. (可选)在ChromeOS上启用Linux支持。
1. 更新并安装依赖
在Debian/Ubuntu系统上执行以下命令安装所有必要的软件包:
bash
sudo apt-get update -y && sudo apt-get upgrade -y
sudo apt-get install -y curl git unzip xz-utils zip libglu1-mesa clang cmake ninja-build pkg-config libgtk-3-dev libstdc++-12-dev2. 可选:ChromeOS配置
- 如果在Chromebook上开发: 在ChromeOS设置中开启Linux支持。在继续之前,确保使用上述命令将Linux容器完全更新。
apt-get
3. IDE配置
安装Visual Studio Code、Android Studio或基于IntelliJ的IDE。安装官方的Dart和Flutter扩展/插件,以启用语言服务器功能和调试能力。
Workflow: Validating the Environment
工作流:验证环境
Run this feedback loop to ensure the toolchain is correctly recognized by the Flutter SDK.
Task Progress:
- 1. Run environment validator.
- 2. Verify connected Linux devices.
- 3. Resolve toolchain errors.
1. Run Validator
Execute the Flutter diagnostic tool with verbose output:
bash
flutter doctor -v2. Review and Fix (Feedback Loop)
- If errors exist under the "Linux toolchain" section: Review the missing dependencies, install the flagged packages, and re-run . Repeat until the Linux toolchain section passes.
flutter doctor -v
3. Verify Device Availability
Ensure the Linux desktop is recognized as a valid deployment target:
bash
flutter devicesExpected Output: At least one entry must display with the platform marked as linux.
运行以下反馈循环以确保Flutter SDK能正确识别工具链。
任务进度:
- 1. 运行环境验证工具。
- 2. 验证已连接的Linux设备。
- 3. 解决工具链错误。
1. 运行验证工具
执行带详细输出的Flutter诊断工具:
bash
flutter doctor -v2. 检查并修复(反馈循环)
- 如果“Linux toolchain”部分存在错误: 检查缺失的依赖,安装标记的软件包,然后重新运行。重复此步骤直到Linux toolchain部分通过验证。
flutter doctor -v
3. 验证设备可用性
确保Linux桌面被识别为有效的部署目标:
bash
flutter devices预期输出: 至少有一个条目显示平台为linux。
Workflow: Preparing for Distribution (Snapcraft)
工作流:为发布做准备(Snapcraft)
When preparing a release build for the Snap Store, configure the Snapcraft build environment.
Task Progress:
- 1. Install Snapcraft and LXD.
- 2. Configure LXD.
- 3. Build the Snap package.
1. Install Build Tools
bash
sudo snap install snapcraft --classic
sudo snap install lxd2. Configure LXD
Initialize LXD and add the current user to the group:
lxdbash
sudo lxd init
sudo usermod -a -G lxd <your_username>Note: Log out and log back in to apply the group changes.
3. Build the Snap
Navigate to the project root containing the file and execute the build:
snap/snapcraft.yamlbash
snapcraft --use-lxd当准备为Snap Store构建发布版本时,配置Snapcraft构建环境。
任务进度:
- 1. 安装Snapcraft和LXD。
- 2. 配置LXD。
- 3. 构建Snap包。
1. 安装构建工具
bash
sudo snap install snapcraft --classic
sudo snap install lxd2. 配置LXD
初始化LXD并将当前用户添加到组:
lxdbash
sudo lxd init
sudo usermod -a -G lxd <your_username>注意:注销并重新登录以应用组更改。
3. 构建Snap包
导航到包含文件的项目根目录并执行构建命令:
snap/snapcraft.yamlbash
snapcraft --use-lxdExamples
示例
Baseline snapcraft.yaml
Configuration
snapcraft.yaml基础snapcraft.yaml
配置
snapcraft.yamlUse this template for the file when packaging a Flutter Linux app for the Snap Store.
<project_root>/snap/snapcraft.yamlyaml
name: super-cool-app
version: 0.1.0
summary: Super Cool App
description: Super Cool App that does everything!
confinement: strict
base: core22
grade: stable
slots:
dbus-super-cool-app:
interface: dbus
bus: session
name: org.bar.super_cool_app
apps:
super-cool-app:
command: super_cool_app
extensions: [gnome]
plugs:
- network
slots:
- dbus-super-cool-app
parts:
super-cool-app:
source: .
plugin: flutter
flutter-target: lib/main.dart当为Snap Store打包Flutter Linux应用时,可使用此模板作为文件。
<project_root>/snap/snapcraft.yamlyaml
name: super-cool-app
version: 0.1.0
summary: Super Cool App
description: Super Cool App that does everything!
confinement: strict
base: core22
grade: stable
slots:
dbus-super-cool-app:
interface: dbus
bus: session
name: org.bar.super_cool_app
apps:
super-cool-app:
command: super_cool_app
extensions: [gnome]
plugs:
- network
slots:
- dbus-super-cool-app
parts:
super-cool-app:
source: .
plugin: flutter
flutter-target: lib/main.dart