flutter-setting-up-on-windows

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Setting Up Flutter for Windows Development

为Windows开发搭建Flutter环境

Contents

目录

Core Requirements

核心要求

Configure the Windows environment to support both Flutter framework execution and native C/C++ compilation. Differentiate strictly between Visual Studio (required for Windows desktop C++ compilation) and VS Code (the recommended Dart/Flutter code editor).
配置Windows环境以支持Flutter框架运行和原生C/C++编译。严格区分Visual Studio(Windows桌面C++编译必需)和VS Code(推荐的Dart/Flutter代码编辑器)。

Workflow: Installing and Configuring the SDK

流程:安装和配置SDK

Follow this sequential workflow to initialize the Flutter SDK on a Windows machine.
  • Download the latest stable Flutter SDK for Windows.
  • Extract the SDK to a directory with standard user privileges (e.g.,
    C:\src\flutter
    ). Do not install in protected directories like
    C:\Program Files\
    .
  • Copy the absolute path to the Flutter SDK's
    bin
    directory.
  • Open Windows Environment Variables settings and append the
    bin
    directory path to the system or user
    PATH
    variable.
  • Open a new terminal session to apply the
    PATH
    changes.
  • Feedback Loop: Run validator -> review errors -> fix.
    1. Execute
      flutter doctor -v
      .
    2. Review the output for missing dependencies or path issues.
    3. Resolve any flagged errors before proceeding to tooling setup.
按照以下顺序流程在Windows机器上初始化Flutter SDK。
  • 下载适用于Windows的最新稳定版Flutter SDK。
  • 将SDK解压到具有标准用户权限的目录(例如
    C:\src\flutter
    )。不要安装在受保护目录如
    C:\Program Files\
    中。
  • 复制Flutter SDK的
    bin
    目录的绝对路径。
  • 打开Windows环境变量设置,将
    bin
    目录路径添加到系统或用户
    PATH
    变量中。
  • 打开新的终端会话以应用
    PATH
    更改。
  • 反馈循环: 运行验证工具 -> 查看错误 -> 修复问题。
    1. 执行
      flutter doctor -v
    2. 查看输出中的缺失依赖项或路径问题。
    3. 在进行工具配置前解决所有标记的错误。

Workflow: Configuring Tooling and IDEs

流程:配置工具与IDE

  • Install Visual Studio (not VS Code).
  • Select and install the Desktop development with C++ workload during the Visual Studio installation process. This is mandatory for compiling Windows desktop applications.
  • Install your preferred code editor (VS Code, Android Studio, or IntelliJ).
  • Install the official Flutter and Dart extensions/plugins within your chosen editor.
  • 安装Visual Studio(不是VS Code)。
  • 在Visual Studio安装过程中选择并安装使用C++的桌面开发工作负载。这是编译Windows桌面应用的必需项。
  • 安装你偏好的代码编辑器(VS Code、Android Studio或IntelliJ)。
  • 在所选编辑器中安装官方的Flutter和Dart扩展/插件。

Workflow: Configuring Target Platforms

流程:配置目标平台

Apply conditional logic based on the specific platform you are targeting for development.
If targeting Windows Desktop:
  • Ensure the Visual Studio C++ workload is fully updated.
  • Restart your IDE so it detects the Windows desktop device.
  • To disable platforms you do not intend to compile for, execute
    flutter config --no-enable-<platform>
    (e.g.,
    flutter config --no-enable-windows-desktop
    ).
If targeting Android on Windows:
  • For physical devices: Enable Developer Options and USB debugging on the device. Install the specific OEM USB drivers for Windows.
  • For emulators: Open the Android Virtual Device (AVD) manager. Under "Emulated Performance" -> "Graphics acceleration", select an option specifying "Hardware" to enable hardware acceleration.
  • Verify the device connection by running
    flutter devices
    .
根据你要开发的特定平台应用条件逻辑。
如果目标是Windows桌面:
  • 确保Visual Studio C++工作负载已完全更新。
  • 重启IDE以使其检测到Windows桌面设备。
  • 要禁用你不打算编译的平台,执行
    flutter config --no-enable-<platform>
    (例如
    flutter config --no-enable-windows-desktop
    )。
如果目标是Windows上的Android:
  • 对于物理设备: 在设备上启用开发者选项和USB调试。为Windows安装特定的OEM USB驱动。
  • 对于模拟器: 打开Android虚拟设备(AVD)管理器。在"模拟性能"->"图形加速"下,选择指定"硬件"的选项以启用硬件加速。
  • 通过运行
    flutter devices
    验证设备连接。

Workflow: Building and Packaging for Windows

流程:为Windows构建和打包

To distribute a Windows desktop application, assemble the compiled executable and its required dependencies into a single distributable archive.
  • Execute
    flutter build windows
    to compile the release build.
  • Navigate to
    build\windows\runner\Release\
    .
  • Create a new staging directory for the distribution zip.
  • Copy the following assets from the
    Release
    directory into the staging directory:
    • The application executable (
      .exe
      ).
    • All generated
      .dll
      files.
    • The entire
      data
      directory.
  • Copy the required Visual C++ redistributables into the staging directory alongside the executable:
    • msvcp140.dll
    • vcruntime140.dll
    • vcruntime140_1.dll
  • Compress the staging directory into a
    .zip
    file for distribution.
要分发Windows桌面应用,需将编译后的可执行文件及其所需依赖项组装成单个可分发压缩包。
  • 执行
    flutter build windows
    以编译发布版本。
  • 导航到
    build\windows\runner\Release\
    目录。
  • 为分发压缩包创建一个新的临时目录。
  • Release
    目录中的以下资源复制到临时目录:
    • 应用可执行文件(
      .exe
      )。
    • 所有生成的
      .dll
      文件。
    • 整个
      data
      目录。
  • 将所需的Visual C++可再发行组件复制到临时目录中与可执行文件同级的位置:
    • msvcp140.dll
    • vcruntime140.dll
    • vcruntime140_1.dll
  • 将临时目录压缩为
    .zip
    文件以便分发。

Workflow: Generating and Installing Certificates

流程:生成和安装证书

If you require a self-signed certificate for MSIX packaging or local testing, use OpenSSL.
  • Install OpenSSL and add its
    bin
    directory to your
    PATH
    environment variable.
  • Generate a private key:
    openssl genrsa -out mykeyname.key 2048
  • Generate a Certificate Signing Request (CSR):
    openssl req -new -key mykeyname.key -out mycsrname.csr
  • Generate the signed certificate (CRT):
    openssl x509 -in mycsrname.csr -out mycrtname.crt -req -signkey mykeyname.key -days 10000
  • Generate the
    .pfx
    file:
    openssl pkcs12 -export -out CERTIFICATE.pfx -inkey mykeyname.key -in mycrtname.crt
  • Install the
    .pfx
    certificate on the local Windows machine. Place it in the Certificate Store under Trusted Root Certification Authorities prior to installing the application.
如果需要用于MSIX打包或本地测试的自签名证书,请使用OpenSSL。
  • 安装OpenSSL并将其
    bin
    目录添加到你的
    PATH
    环境变量中。
  • 生成私钥:
    openssl genrsa -out mykeyname.key 2048
  • 生成证书签名请求(CSR):
    openssl req -new -key mykeyname.key -out mycsrname.csr
  • 生成已签名证书(CRT):
    openssl x509 -in mycsrname.csr -out mycrtname.crt -req -signkey mykeyname.key -days 10000
  • 生成
    .pfx
    文件:
    openssl pkcs12 -export -out CERTIFICATE.pfx -inkey mykeyname.key -in mycrtname.crt
  • 在本地Windows机器上安装
    .pfx
    证书。在安装应用前,将其放置在受信任的根证书颁发机构下的证书存储中。

Examples

示例

Windows Distribution Directory Structure

Windows分发目录结构

When assembling your Windows build for distribution, ensure the directory structure strictly matches the following layout before zipping:
text
Release_Archive/
│   my_flutter_app.exe
│   flutter_windows.dll
│   msvcp140.dll
│   vcruntime140.dll
│   vcruntime140_1.dll
└───data/
    │   app.so
    │   icudtl.dat
    │   ...
在组装Windows构建版本以进行分发时,确保在压缩前目录结构严格匹配以下布局:
text
Release_Archive/
│   my_flutter_app.exe
│   flutter_windows.dll
│   msvcp140.dll
│   vcruntime140.dll
│   vcruntime140_1.dll
└───data/
    │   app.so
    │   icudtl.dat
    │   ...