本页面收集了关于 Flutter 一些大家常见问题的解答。你可能还会想要查看下面一些特别的答疑:

This page collects some common questions asked about Flutter. You might also check out the following specialized FAQs:

什么是 Flutter?

What is Flutter?

Flutter 是 Google 的便携式 UI 工具包,帮助你在移动、web、桌面端创造高质量的绝妙原生体验的应用。 Flutter 可以和世界上的开发人员和开发组织广泛使用的那些现存代码一起使用,并且是开源的、免费的。

Flutter is Google’s portable UI toolkit for crafting beautiful, natively compiled applications for mobile, web, and desktop from a single codebase. Flutter works with existing code, is used by developers and organizations around the world, and is free and open source.

Flutter 是干什么的?

What does Flutter do?

对于用户来说,Flutter 让漂亮的应用 UI 变得生动有趣。

For users, Flutter makes beautiful app UIs come to life.

对于开发者来说,Flutter 降低了创建移动应用的门槛。它加速了移动应用的开发,降低了兼顾 Android 和 iOS 应用开发的成本和复杂性。

For developers, Flutter lowers the bar to entry for building apps. It speeds up development of apps and reduces the cost and complexity of app production across platforms.

对于设计师而言,Flutter 可以确保精确地实现设计意图,而无需降低保真度或被迫进行妥协。在设计师的手里,Flutter 还可以作为一种高效的原型设计工具。

For designers, Flutter helps deliver the original design vision, without loss of fidelity or compromises. It also acts as a productive prototyping tool.

哪些人会用到 Flutter?

Who is Flutter for?

Flutter 适用于希望快速构建精美的移动应用,或者希望用一套代码库覆盖更多用户的开发者。

Flutter is for developers that want a faster way to build beautiful apps, or a way to reach more users with a single investment.

Flutter 也适用于需要领导研发团队的 工程经理 们。 Flutter 可以让工程经理打造一个统一的应用研发团队,这个“应用”包含:移动端、Web 端以及桌面端。这可以帮助以便更快地开发更多功能,将相同的功能部署到多平台的应用中,并降低维护成本。

Flutter is also for engineering managers that lead development teams. Flutter allows eng managers to create a single mobile, web, and desktop app dev team, unifying their development investments to ship more features faster, ship the same feature set to multiple platforms at the same time, and lower maintenance costs.

虽然设计师群体不是 Flutter 最初的目标受众,但 Flutter 也适用于那些希望将原始设计意图高保真地传递给所有移动用户的设计师。以及,CodePen 现在已经支持 Flutter 啦!

While not the initial target audience, Flutter is also for designers that want their original design visions delivered consistently, with high fidelity, to all users. In fact, CodePen now supports Flutter.

说到底,如果您想要漂亮的应用,令人愉悦的动效和动画,以及富有个性和身份感的 UI,那您就是 Flutter 的目标用户。

Fundamentally, Flutter is for users that want beautiful apps, with delightful motion and animation, and UIs with character and an identity all their own.

对于开发者来说,Flutter 降低了应用开发的入门门槛。它加速了应用开发的过程,减少了跨平台开发的成本以及复杂度。

For developers, Flutter lowers the bar to entry for building apps. It speeds app development and reduces the cost and complexity of app production across platforms.

对于设计师来说,Flutter 提供了一个能够实现高保真度用户体验的画布。 Fast 公司评价 Flutter 是 [一个设计灵感的源泉][one of the top design ideas of the decade],提供了将概念转换为生产代码的能力,却没有典型的框架强加的妥协。

For designers, Flutter provides a canvas for high-end user experiences. Fast Company described Flutter as [one of the top design ideas of the decade][] for its ability to turn concepts into production code without the compromises imposed by typical frameworks. It also acts as a productive prototyping tool, with CodePen support for sharing your ideas with others.

对于工程主管以及雇主来说,Flutter 可以将不同平台的应用开发者,统一为一个 移动端、前端和桌面端应用程序 的团队,共同建立品牌,并在单个代码库中打造的多个平台的应用程序。 Flutter 加速了跨平台下开发以及同步发布进程的开发进度。

For engineering managers and businesses, Flutter allows the unification of app developers into a single mobile, web, and desktop app team, building branded apps for multiple platforms out of a single codebase. Flutter speeds feature development and synchronizes release schedules across the entire customer base.

我需要拥有怎样的开发经验才能使用 Flutter?

How experienced of a programmer/developer do I have to be to use Flutter?

如果您熟悉面向对象概念 (类、方法、变量等) 和指令式编程概念 (循环、条件等) ,您会发现 Flutter 很容易上手。

Flutter is approachable to programmers familiar with object-oriented concepts (classes, methods, variables, etc) and imperative programming concepts (loops, conditionals, etc).

学习和使用 Flutter 无需具备很充足的开发经验。

No prior experience is required in order to learn and use Flutter.

就我们亲历过的例子来说,编程经验并不丰富的人们一样可以学习并使用 Flutter 进行原型设计和应用开发。

We have seen people with very little programming experience learn and use Flutter for prototyping and app development.

我可以用 Flutter 构建怎样的应用?

What kinds of apps can I build with Flutter?

Flutter 设计为了让移动应用能够运行在 Android 与 iOS,以及在 web 和桌面端运行可交互式的应用。(请注意,桌面版支持目前已进入 beta 版本,但你还可以在 stable channel 中获取的 beta 版本的快照)

Flutter is designed to support mobile apps that run on both Android and iOS, as well as interactive apps that you want to run on your web pages or on the desktop. (Note that desktop support is in beta, but a snapshot of the beta is available on the stable channel.)

如果您的应用强烈需要表达出品牌个性,Flutter 会非常适合。不过,即便您想要打造的应用看起来像是股票平台那样复杂,也可以使用 Flutter 来构建。

Apps that need to deliver highly branded designs are particularly well suited for Flutter. However, you can also create pixel-perfect experiences that match the Android and iOS design languages with Flutter.

Flutter 的 软件包生态 支持绝大多数硬件(包括摄像头、GPS、网络以及储存)以及服务(例如支付、云储存、验证以及 广告)。

Flutter’s package ecosystem supports a wide variety of hardware (such as camera, GPS, network, and storage) and services (such as payments, cloud storage, authentication, and ads).

Flutter 可以构建功能齐全的应用,包括使用摄像头、地理位置、网络、存储、第三方 SDK 等。

You can build full-featured apps with Flutter, including camera, geolocation, network, storage, 3rd-party SDKs, and more.

谁创造了 Flutter?

Who makes Flutter?

Flutter 是一个开源项目,由 Google 和开发社区共同创造。

Flutter is an open source project, with contributions from Google and other companies and individuals.

谁在使用 Flutter?

Who uses Flutter?

Google 内部和外部的开发者使用 Flutter 为 Android 和 iOS 构建精美的原生应用。您可以访问 案例页面 来了解一些知名的开发者 / 组织。

Developers inside and outside of Google use Flutter to build beautiful natively-compiled apps for iOS and Android. To learn about some of these apps, visit the showcase.

Flutter 有哪些独到之处?

What makes Flutter unique?

Flutter 与大多数用来构建移动应用的工具不同,因为它既不使用 WebView,也不使用设备附带的 OEM Widget,而是使用自己的高性能渲染引擎来绘制 Widget。

Flutter is different than most other options for building mobile apps because it doesn’t rely on web browser technology nor the set of widgets that ship with each device. Instead, Flutter uses its own high-performance rendering engine to draw widgets.

Flutter 与其它工具的不同之处还在于,它只有一层简洁的 C/C++ 代码,在这之上,Flutter 使用 Dart (一种现代化的、简洁的面向对象语言) 实现其大部分系统功能 (布局、手势、动画、框架、Widget 等),这种语言使得开发者可以轻松地进行阅读、更改、替换或删除。这些特性都为开发者提供了巨大的系统控制权限,同时显著降低了访问大多数系统功能的门槛。

In addition, Flutter is different because it only has a thin layer of C/C++ code. Flutter implements most of its system (compositing, gestures, animation, framework, widgets, etc) in [Dart][] (a modern, concise, object-oriented language) that developers can easily approach read, change, replace, or remove. This gives developers tremendous control over the system, as well as significantly lowers the bar to approachability for the majority of the system.

我需要使用 Flutter 来构建我的下一个应用吗?

Should I build my next production app with Flutter?

Flutter 1.0 已于 2018 年 12 月推出,Flutter 2 在 2021 年 3 月 3 日发布。至今为止,成千上万使用了 Flutter 的应用已经被安装到了数亿台设备中。请通过成功 案例页面 了解知名开发者们的成果。

Flutter 1.0 was launched on Dec 4th, 2018 and Flutter 2 on March 3rd, 2021. Since then, over 100,000 apps have shipped using Flutter to many hundreds of millions of devices. See some sample apps in the showcase.

Flutter 进行了高质量的持续交付更新,优化了稳定性、性能以及一些常见的用户需求。

Flutter ships updates on a roughly-quarterly cadence that improve stability and performance and address commonly-requested user features.

Flutter 能够为我们提供什么?

What does Flutter provide?

Flutter SDK 里有什么?

What is inside the Flutter SDK?

Flutter 包括了:

Flutter includes:

  • 高度优化的针对移动应用的 2D 渲染引擎,更具备出色的文字支持功能

    Heavily optimized, mobile-first 2D rendering engine with excellent support for text

  • 现代化的 react 风格框架

    Modern react-style framework

  • 丰富的 widgets,很好的实现了 Material Design 风格及 iOS 风格。

    Rich set of widgets implementing Material Design and iOS-style.

  • 用于单元和集成测试的 API

    APIs for unit and integration tests

  • 用于连接系统和第三方 SDK 的互操作及插件 API

    Interop and plugin APIs to connect to the system and 3rd-party SDKs

  • 无界面 (headless) 测试运行器,用于在 Windows、Linux 和 Mac 上运行测试

    Headless test runner for running tests on Windows, Linux, and Mac

  • Dart DevTools 用以测试、调试和分析你的应用

    Dart DevTools for testing, debugging, and profiling your app

  • 命令行工具,用于创建、构建、测试和编译应用

    Command-line tools for creating, building, testing, and compiling your apps

用 Flutter 开发时可以使用哪些编辑器或 IDE?

Does Flutter work with any editors or IDEs?

可以通过插件的方式使用 Android StudioIntelliJ IDEAVS Code 开发 Flutter 应用。请参阅 边界配置 以了解如何初始化,以及 Android Studio/IntelliJVS Code 如何使用 plugin 的小提示。

We provide plugins for Android Studio, IntelliJ IDEA, and VS Code. See editor configuration for setup details, and Android Studio/IntelliJ and VS Code for tips on how to use the plugins.

有关设置的详细信息,请参阅 编辑器配置文档,以及使用 Android Studio/IntelliJVS Code 插件的小提示。

See editor configuration for setup details, and Android Studio/IntelliJ and VS Code for tips on how to use the plugins.

您也可以在命令行中使用 flutter 命令,并配合能编辑 Dart 语言的编辑器 进行开发。

Alternatively, you can use the flutter command from a terminal, along with one of the many editors that support editing Dart.

Flutter 里存在开发框架吗?

Does Flutter come with a framework?

是的,Flutter 自带了现代化的开发框架,灵感正是来自 React。 Flutter 的框架旨在实现分层、可定制 (以及灵活的开发选项)。开发者可以选择仅使用框架的一部分,或是使用另外的框架。

Yes! Flutter ships with a modern react-style framework. Flutter’s framework is designed to be layered and customizable (and optional). Developers can choose to use only parts of the framework, or even replace upper layers of the framework entirely.

Flutter 里存在 Widget 吗?

Does Flutter come with widgets?

是的,Flutter 自带了一套 高品质的 Material Design 和 Cupertino (iOS 风格) Widget、布局和主题。当然,这些 Widget 只是一个起点。Flutter 的设计目的就是,让您轻松创建自己的 Widget,或是定制现有的 Widget。

Yes! Flutter ships with a set of high-quality Material Design and Cupertino (iOS-style) widgets, layouts, and themes. Of course, these widgets are only a starting point. Flutter is designed to make it easy to create your own widgets, or customize the existing widgets.

Flutter 支持 Material 主题定制 (Theming) 吗?

Does Flutter support Material Theming?

是的,Flutter 和 Material 团队密切合作,完全支持 Material Theming。你可以通过 codelab 了解 Material 组件 (MDC) 主题定制:MDC-103 Flutter: Material Theming

Yes! The Flutter and Material teams collaborate closely, and Material is fully supported. A number of examples of this are shown in the MDC-103 Flutter: Material Theming codelab.

Flutter 带有测试框架吗?

Does Flutter come with a testing framework?

是的,Flutter 提供用于编写单元和集成测试的 API。了解更多有关 Flutter 测试的信息请查看 测试 Flutter 应用

Yes, Flutter provides APIs for writing unit and integration tests. Learn more about testing with Flutter.

我们使用自己的测试功能来测试我们的 SDK,每次提交代码前我们都会测量提交的 测试覆盖率

We use our own testing capabilities to test our SDK, and we measure our test coverage on every commit.

Flutter 是否附带调试工具?

Does Flutter come with debugging tools?

Flutter 本身不附带调试工具,但我们有非常多可用的调试工具能够帮助你调试 Flutter 应用。你可以在 调试 Flutter 文章中了解更多信息。

Yes, Flutter comes with Flutter DevTools (also called Dart DevTools). For more information, see Debugging with Flutter and the Flutter DevTools docs.

Flutter 是否带有依赖注入 (dependency injection) 的框架或解决方案?

Does Flutter come with a dependency injection framework or solution?

我们并没有提供相关解决方案,但是这里有许多包提供了依赖注入或服务定位的能力,例如 [injectable][], [get_it][], 和 [kiwi][].

We don’t ship with an opinionated solution, but there are a variety of packages that offer dependency injection and service location, such as [injectable][], [get_it][], and [kiwi][].



Flutter 是使用什么技术构建的?

What technology is Flutter built with?

Flutter 使用 C、C++、Dart 和 Skia (2D 渲染引擎) 构建。您可以参阅下面这张 架构图 来理解其主要构建。若您需要了解 Flutter 的分层架构,请阅读 [架构概览][architectural overview]。

Flutter is built with C, C++, Dart, and Skia (a 2D rendering engine). See this architecture diagram for a better picture of the main components. For a more detailed description of the layered architecture of Flutter, read the [architectural overview].

Flutter 如何在 Android 上运行我的代码?

How does Flutter run my code on Android?

引擎的 C 和 C++ 代码使用 Android 的 NDK 编译。 Dart 代码 (SDK 的和您写的) 都是预先 (ahead-of-time, AOT) 编译成本地 ARM 及 x86 库。这些库被包含在一个 Android “runner” 项目中,然后整套内容被编译成一个 APK。当应用启动时,它会加载 Flutter 库。任何渲染、输入或事件处理等都会 delegate 给编译好的 Flutter 和应用代码。这个工作机制与很多游戏引擎颇为相似。

The engine’s C and C++ code are compiled with Android’s NDK. The Dart code (both the SDK’s and yours) are ahead-of-time (AOT) compiled into native, ARM, and x86 libraries. Those libraries are included in a “runner” Android project, and the whole thing is built into an .apk. When launched, the app loads the Flutter library. Any rendering, input, or event handling, and so on, is delegated to the compiled Flutter and app code. This is similar to the way many game engines work.

调试模式时,Flutter 使用虚拟机 (VM) 来运行 Dart 代码(因此这时会显示 “Debug” 字样,以提醒开发者速度会稍微变慢),这样便可以启用有状态热重载 (Stateful Hot Reload),它能够让你无需重新编译整个应用就能看到代码变更带来的变化。当运行该模式时,你可以看到一个 “debug” banner 在你应用的右上角。请记住,这时的性能并不是最终发布应用时的性能。

During debug mode, Flutter uses a virtual machine (VM) to run its code in order to enable stateful hot reload, a feature that lets you make changes to your running code without recompilation. You’ll see a “debug” banner in the top right-hand corner of your app when running in this mode, to remind you that performance is not characteristic of the finished release app.

Flutter 如何在 iOS 上运行我的代码?{#run-ios}

How does Flutter run my code on iOS?

引擎的 C 和 C++ 代码使用 LLVM 编译。Dart 代码 (SDK 的和您的) 都是预先 (ahead-of-time, AOT) 编译成本地 ARM 库。这些库被包含在一个 iOS “runner” 项目中,然后整套内容被编译成一个 .ipa。当应用启动时,它会加载 Flutter 库。任何渲染、输入或事件处理等都会代理给编译好的 Flutter 和应用代码。这个工作机制与很多游戏引擎颇为相似。

The engine’s C and C++ code are compiled with LLVM. The Dart code (both the SDK’s and yours) are ahead-of-time (AOT) compiled into a native, ARM library. That library is included in a “runner” iOS project, and the whole thing is built into an .ipa. When launched, the app loads the Flutter library. Any rendering, input or event handling, and so on, are delegated to the compiled Flutter and app code. This is similar to the way many game engines work.

Flutter 是否会使用系统的 OEM widget?

Does Flutter use my system’s OEM widgets?

不会。相反,Flutter 自己提供了一套 widget (包括 Material Design 和 iOS 风格的 Cupertino widget),由 Flutter 的框架和引擎负责管理和渲染。你可以在这里浏览 Flutter widget 目录

No. Instead, Flutter provides a set of widgets (including Material Design and Cupertino (iOS-styled) widgets), managed and rendered by Flutter’s framework and engine. You can browse a catalog of Flutter’s widgets.

我们希望最终能够产生出更高质量的应用。如果我们直接使用 OEM 自带的 widget,那么 Flutter 应用的质量和性能将受到这些 widget 质量的限制。

We believe that the end result is higher quality apps. If we reused the built-in platform widgets, the quality and performance of Flutter apps would be limited by the flexibility and quality of those widgets.

例如,在 Android 中,有一组硬编码的手势和固定的计算规则来区别它们。在 Flutter 中,您可以编写自己的手势识别器,它在 手势系统 中拥有最高的优先级。此外,由不同人创作的两个 widget 可以进行协调,以便消除手势的歧义。

In Android, for example, there’s a hard-coded set of gestures and fixed rules for disambiguating them. In Flutter, you can write your own gesture recognizer that is a first class participant in the gesture system. Moreover, two widgets authored by different people can coordinate to disambiguate gestures.

如今的应用设计趋势表明,很多设计师和用户都需要动效丰富的 UI,同时富有品牌表现力。为了实现这种级别的美学定制化设计,Flutter 在架构上就会倾向于直接驱动像素,而不是交给 OEM widget 来处理。

Modern app design trends point towards designers and users wanting more motion-rich UIs and brand-first designs. In order to achieve that level of customized, beautiful design, Flutter is architectured to drive pixels instead of the built-in widgets.

由于使用相同的渲染器、框架和 widget,就意味着您能更加轻松地同时发布 iOS 和 Android 版本应用,而无需耗费精力和成本来规划和同步两套独立的代码库和功能集。

By using the same renderer, framework, and set of widgets, it’s easier to publish for multiple platforms from the same codebase, without having to do careful and costly planning to align different feature sets and API characteristics.

另外,使用单一的语言、单个框架和同一组适用于所有 UI 的库 (无论您的 UI 在每个移动平台上都各有不同还是基本一致),也有助于帮助您降低应用开发和维护成本。

By using a single language, a single framework, and a single set of libraries for all of your code (regardless if your UI is different for each platform or not), we also aim to help lower app development and maintenance costs.

我的移动 OS 更新并加入新的 widget 时会怎么样?

What happens when my mobile OS updates and introduces new widgets?

Flutter 团队密切关注来自 iOS 和 Android 的 widget 使用和需求情况,且会与社区合作,对新的 widget 提供构建支持。这些支持可能会以这些形式来提供给开发者: 较低层级的框架功能、新的可编辑组合的 widget,或全新的 widget 实现。

The Flutter team watches the adoption and demand for new mobile widgets from iOS and Android, and aims to work with the community to build support for new widgets. This work might come in the form of lower-level framework features, new composable widgets, or new widget implementations.

Flutter 的分层架构旨在支持众多 widget 库,我们鼓励并支持社区构建和维护 widget 库。

Flutter’s layered architecture is designed to support numerous widget libraries, and we encourage and support the community in building and maintaining widget libraries.

我的移动 OS 更新并加入新的平台功能时会怎么样?

What happens when my mobile OS updates and introduces new platform capabilities?

Flutter 的互操作 (interop) 和插件 (plugin) 系统旨在使开发者能够立即访问新的移动操作系统特性和功能。开发者不必等待 Flutter 团队提供新系统功能的访问接口,而是自己第一时间即可使用。

Flutter’s interop and plugin system is designed to allow developers to access new mobile OS features and capabilities immediately. Developers don’t have to wait for the Flutter team to expose the new mobile OS capability.

我能使用哪些操作系统开发 Flutter 应用?

What operating systems can I use to build a Flutter app?

Flutter 支持使用 Linux、Mac 和 Windows 进行开发。

Flutter supports development using Linux, macOS, ChromeOS, and Windows.

Flutter 是用哪种语言写成的?

What language is Flutter written in?

[Dart][] 是一个现代化高度发展,并为终端应用专门优化的语言。底层图形框架和 Dart 虚拟机在 C/C++ 中实现。

[Dart][], a fast-growing modern language optimized for client apps. The underlying graphics framework and the Dart virtual machine are implemented in C/C++.

During the initial development phase, the Flutter team looked at a lot of languages and runtimes, and ultimately adopted Dart for the framework and widgets. Flutter used four primary dimensions for evaluation, and considered the needs of framework authors, developers, and end users. We found many languages met some requirements, but Dart scored highly on all of our evaluation dimensions and met all our requirements and criteria.

Dart runtimes and compilers support the combination of two critical features for Flutter: a JIT-based fast development cycle that allows for shape changing and stateful hot reloads in a language with types, plus an Ahead-of-Time compiler that emits efficient ARM code for fast startup and predictable performance of production deployments.

In addition, we have the opportunity to work closely with the Dart community, which is actively investing resources in improving Dart for use in Flutter. For example, when we adopted Dart, the language didn’t have an ahead-of-time toolchain for producing native binaries, which is instrumental in achieving predictable, high performance, but now the language does because the Dart team built it for Flutter. Similarly, the Dart VM has previously been optimized for throughput but the team is now optimizing the VM for latency, which is more

Flutter 为什么选择使用 Dart?

Why did Flutter choose to use Dart?

Flutter 使用四个主要维度进行评估,并综合考虑了框架开发者、应用开发者和最终用户的需求。我们发现某些语言的确在某些维度符合要求,但 Dart 在所有评估维度上都取得了高分,并且符合我们的所有要求和标准。

Flutter used four primary dimensions for evaluation, and considered the needs of framework authors, developers, and end users. We found some languages met some requirements, but Dart scored highly on all of our evaluation dimensions and met all our requirements and criteria.

Dart 的运行时和编译器支持 Flutter 的两个关键特性: 基于 JIT 的快速开发周期,允许在带类型的语言中支持形变和有状态热重载,以及一个能产出高效率 ARM 代码的 AOT 编译器,从而确保快速启动的能力和可预期的生产版本运行性能。

Dart runtimes and compilers support the combination of two critical features for Flutter: a JIT-based fast development cycle that allows for shape changing and stateful hot reloads in a language with types, plus an Ahead-of-Time compiler that emits efficient ARM code for fast startup and predictable performance of production deployments.

此外,我们还有幸与 Dart 社区展开了密切合作,Dart 社区积极投入资源改进 Dart,以便在 Flutter 中更易使用。例如,当我们采用 Dart 时,该语言还没有用于生成原生二进制文件的 AOT 工具链,这些工具有助于实现稳定的高性能表现,但在 Dart 团队为 Flutter 构建了这些工具后,这个缺失已经不复存在了。同样,Dart VM 之前是针对吞吐量进行的优化,但团队现在正在针对延迟进行优化,这对于解决 Flutter 的工作负载更为重要。

In addition, we have the opportunity to work closely with the Dart community, which is actively investing resources in improving Dart for use in Flutter. For example, when we adopted Dart, the language didn’t have an ahead-of-time toolchain for producing native binaries, which is instrumental in achieving predictable, high performance, but now the language does because the Dart team built it for Flutter. Similarly, the Dart VM has previously been optimized for throughput but the team is now optimizing the VM for latency, which is more important for Flutter’s workload.

在评估时,Dart 在以下主要标准上得分很高:

Dart scores highly for us on the following primary criteria:

Developer productivity
One of Flutter’s main value propositions is that it saves engineering resources by letting developers create apps for both iOS and Android with the same codebase. Using a highly productive language accelerates developers further and makes Flutter more attractive. This was very important to both our framework team as well as our developers. The majority of Flutter is built in the same language we give to our users, so we need to stay productive at 100k’s lines of code, without sacrificing approachability or readability of the framework and widgets for our developers.

开发人员生产力:Flutter 的主要价值之一是通过让开发人员用同一套代码创建适用于 iOS 和 Android 的应用而节省开发资源。使用高生产力的语言加速开发,并提升 Flutter 的吸引力。这对于我们的框架团队和开发人员都很重要。 Flutter 本身的大部分内容所用的语言都和我们提供给用户的一样,所以我们要让十万行代码保持生产力,而不会牺牲框架和部件对我们开发人员的可达性和可读性。

For Flutter, we want a language that’s suited to Flutter’s problem domain: creating visual user experiences. The industry has multiple decades of experience building user interface frameworks in object-oriented languages. While we could use a non-object-oriented language, this would mean reinventing the wheel to solve several hard problems. Plus, the vast majority of developers have experience with object-oriented development, making it easier to learn how to develop with Flutter.

面向对象:对于 Flutter 而言,我们需要一种适合其问题域——创建可视化用户体验——的语言。这个领域中沉淀了数十年的面向对象构建 UI 框架的经验。虽然我们可以使用非面向对象语言,但这意味着,为了解决几个难题,我们要 “重新发明轮子”。此外,绝大多数开发者都拥有面向对象开发的经验,因此可以更轻松地学习如何使用 Flutter 进行开发。

Predictable, high performance
With Flutter, we want to empower developers to create fast, fluid user experiences. In order to achieve that, we need to be able to run a significant amount of end-developer code during every animation frame. That means we need a language that both delivers high performance and predictable performance, without periodic pauses that would cause dropped frames.

稳定可期的高性能表现:我们希望开发者能够通过 Flutter 创建快速而流畅的用户体验。为了实现这一点,我们需要能够在每个动画帧期间运行大量的最终开发者代码。这意味着我们需要的语言一方面既要拥有高性能,另一方面又需要避免因周期性的中断而影响帧率,即 “可期性”。

Fast allocation
The Flutter framework uses a functional-style flow that depends heavily on the underlying memory allocator efficiently handling small, short-lived allocations. This style was developed in languages with this property and doesn’t work efficiently in languages that lack this facility.

快速内存分配:Flutter 框架使用的函数式流程,很大程度上依赖于下层的内存分配器高效地对小型的、短生命周期的内容进行内存分配。这个流程是使用支持这种分配机制的语言进行开发的,在缺少这个机制的语言中无法有效运作。

Flutter 可以运行那些没有直接或间接导入了 dart:mirrorsdart:html 的库。

Flutter can run Dart code that doesn’t directly or transitively import dart:mirrors or dart:html.

Flutter 能运行任何 Dart 代码吗?

Can Flutter run any Dart code?

Flutter 应该能够运行大多数没有引用 dart:mirrors 或 dart:html (不论是直接还是间接引用) 的 Dart 代码。

Flutter should be able to run most Dart code that doesn’t import (transitively, or directly) dart:mirrors or dart:html.

Flutter 引擎有多大?

How big is the Flutter engine?

2019 年 7 月,我们实测了一个 最简版本的 Flutter 应用 (即不含 Material 组件,只包含一个使用 flutter build apk --split-per-abi 构建的 Center widget 的 app) 压缩且 Bundle 一个 release 的 APK, ARM64 下是 4.6 MB,ARM 下是 4.3 MB。

In July 2019, we measured the download size of a minimal Flutter app (no Material Components, just a single Center widget, built with flutter build apk --split-per-abi), bundled and compressed as a release APK, to be approximately 4.3 MB for ARM, and 4.6 MB for ARM 64.

在 ARM 下,核心的引擎大约占 3.2 MB,框架和应用的代码大约是 920.6 KB,许可证文件大约是 54.3 KB,必要的 Java 代码(classes.dex)是 113.6KB。上述数据均为经过压缩处理之后的大小。

In ARM, the core engine is approximately 3.2 MB (compressed), the framework + app code is approximately 920.6 KB (compressed), the LICENSE file is 54.3 KB (compressed), necessary Java code (classes.dex) is 113.6 KB (compressed).

在 ARM64 下,核心的引擎大约占 3.5 MB,框架和应用的代码大约是 872 KB,许可证文件大约是 54.3 KB,必要的 Java 代码(classes.dex)是 113.6KB。上述数据均为经过压缩处理之后的大小。

In ARM64, the core engine is approximately 3.5 MB (compressed), the framework + app code is approximately 872 KB (compressed), the LICENSE file is 54.3 KB (compressed), necessary Java code (classes.dex) is 113.6 KB (compressed).

这些数字是由 AndroidStudio 内置的 apkanalyzer 实测得出。

These numbers were measured using apkanalyzer, which is also built into Android Studio.

在 iOS 平台上,跟据 App Store Connect 的数据,同一应用的发布 IPA 在 iPhone X 上的下载文件体积为 10.9 MB。 IPA 比 APK 大,主要是因为 Apple 加密了 IPA 中的二进制文件,使得压缩效率降低。(可以查看 iOS App Store Specific ConsiderationsQA1795 关于加密的部分)

On iOS, a release IPA of the same app has a download size of 10.9 MB on an iPhone X, as reported by Apple’s App Store Connect. The IPA is larger than the APK mainly because Apple encrypts binaries within the IPA, making the compression less efficient (see the iOS App Store Specific Considerations section of Apple’s QA1795).

Release 模式下引擎二进制产物将包含 LLVM 的中间语言表示(bitcode)。 Xcode 将使用 bitcode 为 App Store 生成最终包含了最新的编译器优化和功能的二进制文件。 Profile 和 Debug 模式下的 Framework 中,bitcode 部分仅包含 bitcode marker,因此更能代表引擎的真实大小。无论你是否使用 bitcode,release 模式下增加的包大小都会在应用归档后并发布到应用商店后,在构建的最终步骤里被移除。

The release engine binary includes LLVM IR (bitcode). Xcode uses this bitcode to produce a final binary for the App Store containing the latest compiler optimizations and features. The profile and debug frameworks contain only a bitcode marker, and are more representative of the engine’s actual binary size. Whether you ship with bitcode or not, the increased size of the release framework is stripped out during the final steps of the build. These steps happen after archiving your app and shipping it to the store.

当然,您的实际情况可能跟我们所说的有所不同,我们建议您测量自己的应用的体积。想要测量 Android 应用体积,请运行 flutter build apk,(使用 1.7.8+hotfix.3 之后版本的 Flutter,请加入 --split-per-abi 参数)并将 APK (build/app/outputs/apk/release/app-release.apk) 加载到 Android Studio 中,以便获取详细的体积报告。想要测量 iOS 应用,请将发布 IPA 加载到 App Store Connect 并获取体积报告。你可以查看 使用 Android Studio 加载 APK 的相关说明,以及 使用 App Store Connect 加载 IPA 的相关说明。

Of course, we recommend that you measure your own app. To do that, see Measuring your app’s size.



Flutter 应用会拥有怎样的性能表现?

What kind of app performance can I expect?

Flutter 应用会有很出色的性能。Flutter 设计的目标就是帮助开发者轻松实现 60fps 的稳定帧率。 Flutter 应用通过本地编译的代码运行—不涉及解释过程。这也意味着 Flutter 应用启动会非常快捷。

You can expect excellent performance. Flutter is designed to help developers easily achieve a constant 60fps. Flutter apps run via natively compiled code—no interpreters are involved. This means that Flutter apps start quickly.

开发 Flutter 时的操作周期有多长?修改代码和看到界面内容更新之间会隔多久?

What kind of developer cycles can I expect? How long between edit and refresh?

Flutter 使用的是热重载式的开发操作周期。您在实机或者模拟器上都能实现亚秒级的修改-更新速度。

Flutter implements a hot reload developer cycle. You can expect sub-second reload times, on a device or an emulator/simulator.

另外,Flutter 的热重载是有状态的 (stateful),这意味着重新加载后 app 的状态会被保留。这样即使您修改的界面在应用很深的位置,重载后您也能直接看到修改后的该界面,而无需从应用首页开始重新操作。

Flutter’s hot reload is stateful, which means the app state is retained after a reload. This means you can quickly iterate on a screen deeply nested in your app, without starting from the home screen after every reload.

热重载 hot reload 相比较热重启 hot restart 的区别在哪里?

How is hot reload different from hot restart?

通过将更新的源代码文件注入到正在运行的 Dart VM(虚拟机)中来进行热重载。这不仅会添加新的类,还会向现有的类中添加方法和字段,并更改现有的函数。热重启后会将状态重置为应用程序的初始状态。

Hot reload works by injecting updated source code files into the running Dart VM (Virtual Machine). This doesn’t only add new classes, but also adds methods and fields to existing classes, and changes existing functions. Hot restart resets the state to the app’s initial state.


For more information, see Hot reload.

我能把 Flutter 应用部署到哪里?

Where can I deploy my Flutter app?

您可以将 Flutter 应用编译并部署到 iOS 和 Android 平台,亦可部署到 web 平台,当然还有 桌面端(目前处于 beta 阶段)。一些比较激进的开发者已经部署了 Flutter 桌面应用,如果你觉得当前还不想要那么冒险,你也许想要等桌面支持合并到 stable channel。(然而我们已经将 beta 版桌面支持的快照发布在了 stable channel,供你们尝鲜。)

You can compile and deploy your Flutter app to iOS, Android, web, and desktop (in beta). While more adventurous developers are already deploying Flutter desktop apps, you might want to wait for desktop support to migrate to the stable channel if you are uncomfortable living on the edge. (However, a snapshot of beta desktop support is available on the stable channel, so you can try it out.)


How can I find the more users for my app?


App Campaigns connect you with the right user, at the right time.

  • 在谷歌搜索、商店、YouTube、Gmail 以及谷歌展示网络中推广你的应用以吸引更多用户。

    Reach more users by promoting your app across Google Search, Play, YouTube, Gmail, and Google Display Network.

  • 通过为效果最好的广告分配更多预算优化你的出价。您需要为其设置应用安装出价,也就是“目标每次安装费用”,同时设置每日推广支出预算(CPI),剩下的工作交给 Google 处理即可。

    Optimize your budget by allocating more budget to the highest-performing ads. Simply set a target cost-per-install (CPI) and daily budget, and let Google handle the rest.

  • 从应用商店列表中获得即时广告预览,仅需10分钟即可完成设置。下面你可以设置自定义文本内容与投放区域。

    Get set up in 10 minutes with an instant ad preview pulled from your app store listing. Then, customize the text and locations.

获取 75 美元的赠金(当你消费 25 美金后)

Get $75 app advertising credit when you spend $25.

Flutter 可以运行在哪些设备,哪些操作系统版本上?

What devices and OS versions does Flutter run on?

  • 我们会为各种从低端到高端的平台进行支持并且加入测试。您可以查看 已支持的平台 以了解已测试的平台列表。

    We support and test running Flutter on a variety of low-end to high-end platforms. For a detailed list of the platforms on which we test, see the list of supported platforms.

  • Flutter 支持在 x86_64armeabi-v7aarm64-v8a 架构下构建为 ahead-of-time (AOT) 库。

    Flutter supports building ahead-of-time (AOT) compiled libraries for x86_64, armeabi-v7a, and arm64-v8a.

  • 为 ARMv7 或 ARM64 构建的应用在很多 x86 Android 设备上运行良好 (使用 ARM 模拟器)。

    Apps built for ARMv7 or ARM64 run fine (using ARM emulation) on many x86 Android devices.

  • 我们支持在不同的平台上开发 Flutter 应用,请参阅 不同操作系统下安装 Flutter 的方法文档 了解更多。

    We support developing Flutter apps on a range of platforms. See the system requirements listed under each development operating system.

Flutter 能在 Web 上运行吗?

Does Flutter run on the web?

可以的,目前 stable channel 已经支持 web 平台了。你可以将已有的 Flutter 代码编译在 web 运行。更多详细信息,请参阅 Web 介绍

Yes, web support is available in the stable channel. You can compile existing Flutter code to work on the web. For more details, check out the web instructions.

我能使用 Flutter 构建桌面应用吗?

Can I use Flutter to build desktop apps?

Yes, desktop support is in alpha, with macOS being the furthest along. We’re working on making this a first class experience. The current progress is documented on the Desktop page.

可以的,Windows、macOS 以及 Linux 的桌面端的支持目前处于 beta 阶段,但已经在 stable channel 上提供了一份 beta 版本的快照。当前的进度记录在 桌面端支持 页面上查看。

Yes, desktop support is in beta for Windows, macOS, and Linux, but a snapshot of the beta is available on the stable channel.) The current progress is documented on the Desktop page.

我能在我现有的原生应用里使用 Flutter 吗?

Can I use Flutter inside of my existing native app?

是的,你可以在我们网上内的 混合应用 章节中学习。同时,请留意添加 多个 Flutter 页面或 view 体验版已经上线了。

Yes, learn more in the add-to-app section of our website. Also, note that experimental support for adding multiple Flutter screens or views is available.

请参考 [这个文档][add-to-app section],查看如何将 Flutter 加入现有的项目。

See the integration documentation in the add-to-app section of our website.

我能访问传感器、本地存储之类的平台服务和 API 吗?

Can I access platform services and APIs like sensors and local storage?

可以。Flutter 默认即为开发者提供了操作系统中 一些 平台专属服务和 API 的操作入口。但是,我们希望避免大多数跨平台 API 的“最小公约数”问题,因此我们不打算为所有本地服务和 API 构建跨平台的操作 API。

Yes. Flutter gives developers out-of-the-box access to some platform-specific services and APIs from the operating system. However, we want to avoid the “lowest common denominator” problem with most cross-platform APIs, so we don’t intend to build cross-platform APIs for all native services and APIs.

很多平台服务和 API 都在 Pub 站点中提供了 现成的代码包,我们可以根据 说明 使用它们,非常方便。

A number of platform services and APIs have ready-made packages available on pub.dev. Using an existing package is easy.

最后,我们鼓励开发者使用 Flutter 的异步消息传递系统来创建出 自己的平台 与第三方 API 的整合方案。开发者可以根据需要公开尽可能多 (或者尽可能少) 的平台 API,并构建最适合其项目的抽象层。

Finally, we encourage developers to use Flutter’s asynchronous message passing system to create your own integrations with platform and third-party APIs. Developers can expose as much or as little of the platform APIs as they need, and build layers of abstractions that are a best fit for their project.

我能对自带的 widget 进行扩展和定制吗?

Can I extend and customize the bundled widgets?

当然可以。Flutter widget 系统的设计思路就是让开发者可以轻松定制。

Absolutely. Flutter’s widget system was designed to be easily customizable.

Flutter 没有让每个 widget 都提供大量参数,而是采用了组合的方式。较大的 widget 是用较小的 widget 组合构建出来的,您可以重复使用它们,并以新颖的方式对其加以组合,从而生成自定义的 widget。例如,RaisedButton 没有继承自一个通用按钮 widget,而是将 Material widget 与 GestureDetector widget 组合在一起。 Material widget 负责视觉呈现,GestureDetector widget 则实现其交互。

Rather than having each widget provide a large number of parameters, Flutter embraces composition. Widgets are built out of smaller widgets that you can reuse and combine in novel ways to make custom widgets. For example, rather than subclassing a generic button widget, ElevatedButton combines a Material widget with a GestureDetector widget. The Material widget provides the visual design and the GestureDetector widget provides the interaction design.

如果您想要创建自定义设计的按钮,可以将负责视觉呈现的 widget 与提供交互的 GestureDetector 组合起来使用。例如,CupertinoButton 就采用了这种方法,将 GestureDetector 与其他几个负责表现视觉的 widget 进行组合。

To create a button with a custom visual design, you can combine widgets that implement your visual design with a GestureDetector, which provides the interaction design. For example, CupertinoButton follows this approach and combines a GestureDetector with several other widgets that implement its visual design.

这种组合策略使您可以最大限度地控制 widget 的可视化和交互逻辑,同时重复利用大量代码。在框架中,我们将复杂的 widget 分解为实现视觉、交互和动效的各部分。您可以按照自己喜欢的方式重新组合这些 widget,从而制作出自定义 widget 来完整传达出您的设计意图。

Composition gives you maximum control over the visual and interaction design of your widgets while also allowing a large amount of code reuse. In the framework, we’ve decomposed complex widgets to pieces that separately implement the visual, interaction, and motion design. You can remix these widgets however you like to make your own custom widgets that have full range of expression.

我为什么要在 iOS 和 Android 应用间共享布局代码?

Why would I want to share layout code across iOS and Android?

您可以选择为 iOS 和 Android 应用实现不同的布局。开发者可以在运行时检查移动操作系统的种类,并根据操作系统呈现不同的布局,但我们发现这种做法比较少见。

You can choose to implement different app layouts for iOS and Android. Developers are free to check the mobile OS at runtime and render different layouts, though we find this practice to be rare.

我们发现移动应用布局和设计正在不断发展,更趋于品牌设计的诉求,而且跨平台之间的呈现逐渐趋同。这意味着不少开发者会有很强的动力在 iOS 和 Android 上共享布局和 UI 代码。

More and more, we see mobile app layouts and designs evolving to be more brand-driven and unified across platforms. This implies a strong motivation to share layout and UI code across iOS and Android.


The brand identity and customization of the app’s aesthetic design is now becoming more important than strictly adhering to traditional platform aesthetics. For example, app designs often require custom fonts, colors, shapes, motion, and more in order to clearly convey their brand identity.

我们还发现,很多应用都在 iOS 和 Android 上采用了通用的布局模式。例如,您现在可以在 iOS 和 Android 上很方便地找到“底部导航”设计模式。移动平台上的设计理念似乎正在趋于一致。

We also see common layout patterns deployed across iOS and Android. For example, the “bottom nav bar” pattern can now be naturally found across iOS and Android. There seems to be a convergence of design ideas across mobile platforms.


Can I interop with my mobile platform’s default programming language?

可以,Flutter 支持调用 (包括集成) Android 上的 Java 或者 Kotlin 代码,或者 iOS 上的 ObjectiveC 或 Swift 代码。这是通过灵活的消息传递方式实现的, Flutter 应用可以使用 BasicMessageChannel 向移动平台收发消息。

Yes, Flutter supports calling into the platform, including integrating with Java or Kotlin code on Android, and ObjectiveC or Swift code on iOS. This is enabled via a flexible message passing style where a Flutter app might send and receive messages to the mobile platform using a BasicMessageChannel.

如果你想了解有关平台通道的更多信息,可以查阅 platform channels 相关文档。

Learn more about accessing platform and third-party services in Flutter with platform channels.

你也可以通过这个 示例项目,学习如何使用平台通道访问 iOS 和 Android 上的电池状态信息。

Here is an example project that shows how to use a platform channel to access battery state information on iOS and Android.

Flutter 包含反射 / 镜像系统吗?

Does Flutter come with a reflection/mirrors system?

不支持,Dart 的确是含有 dart:mirrors 库,能够提供类型反射。但是由于 Flutter 应用已经针对最终产物进行了预编译,并且控制二进制内容体积始终是现代移动应用需要面对的一个问题,所以我们禁用了 dart:mirrors。

No. Dart includes dart:mirrors, which provides type reflection. But since Flutter apps are pre-compiled for production, and binary size is always a concern with mobile apps, this library is unavailable for Flutter apps.

使用静态类型分析系统,我们可以移除任何不会用到的东西(”得益于 tree shaking 机制”)。如果你导入了一个巨大的 Dart 库,但仅仅用到了一个其中实现的一个两行的函数,那么你只需要付出这两行函数的代价,即便是这个 Dart 库中导入了非常多非常多的库。此保证仅 Dart 可以在编译期安全识别代码路径的情况下。目前,我们已找到其他满足特定需求的方法以提供更好的平衡,如代码生成。

Using static analysis we can strip out anything that isn’t used (“tree shaking”). If you import a huge Dart library but only use a self-contained two-line method, then you only pay the cost of the two-line method, even if that Dart library itself imports dozens and dozens of other libraries. This guarantee is only secure if Dart can identify the code path at compile time. To date, we’ve found other approaches for specific needs that offer a better trade-off, such as code generation.

我应该如何在 Flutter 实现国际化 (internationalization, i18n)、本地化 (localization, l10n) 和可访问性 (accessibility, a11y) ?

How do I do international­ization (i18n), localization (l10n), and accessibility (a11y) in Flutter?

关于国际化和本地化,请查看教程: Flutter 应用里的国际化

Learn more about i18n and l10n in the internationalization tutorial.

关于可访问性 / 无障碍使用,请查看文档:无障碍

Learn more about a11y in the accessibility documentation.

我如何为 Flutter 开发并行 (parallel) 和/或并发 (concurrent) 应用?

How do I write parallel and/or concurrent apps for Flutter?

Flutter 支持 isolate,一个个的 isolate 是 Flutter VM 里彼此独立的堆 (heap),可以并行运行 (通常以独立线程的形式实现)。 Isolate 之间通过异步收发消息来进行通信。

Flutter supports isolates. Isolates are separate heaps in Flutter’s VM, and they are able to run in parallel (usually implemented as separate threads). Isolates communicate by sending and receiving asynchronous messages.

你可以点击链接查看 在 Flutter 中使用 isolate 的示例

Check out an example of using isolates with Flutter.

我能在 Flutter 应用后台运行 Dart 代码吗?

Can I run Dart code in the background of an Flutter app?

可以,你可以在 iOS 和 Android 后台进程中运行 Dart 代码。有关更多信息,你可以查看在 Medium 上的文章: 使用 Flutter 插件和 Geofencing 在后台运行 Dart 代码

Yes, you can run Dart code in a background process on both iOS and Android For more information, see the free Medium article Executing Dart in the Background with Flutter Plugins and Geofencing.

我在 Flutter 里能使用 JSON/XML/protobuffers 等内容吗?

Can I use JSON/XML/protobuffers, etc. with Flutter?

当然可以。Pub 站点 提供了很多这样的代码库,包括 JSON, XML, protobufs 以及很多其他内容格式。

Absolutely. There are libraries on the pub.dev for JSON, XML, protobufs, and many other utilities and formats.

有关在 Flutter 中使用 JSON 的详细介绍,你可以查看 [使用 JSON 的教程][the JSON tutorial]。

For a detailed writeup on using JSON with Flutter, check out the JSON tutorial.

我能用 Flutter 构建 3D (OpenGL) 应用吗?

Can I build 3D (OpenGL) apps with Flutter?

我们暂不支持通过 OpenGL ES 或类似的机制实现 3D。在 3D API 方面我们有一个长期的计划,但目前我们专注于呈现 2D。

Today we don’t support for 3D via OpenGL ES or similar. We have long-term plans to expose an optimized 3D API, but right now we’re focused on 2D.

我的 APK 或 IPA 为什么这么大?

Why is my APK or IPA so big?

通常,图像、声音文件、字体等资源在 APK 或 IPA 里占据了相当的比重。Android 和 iOS 生态系统中有很多工具可以帮助您了解 APK 或 IPA 中的各种内容的比重情况。

Usually, assets including images, sound files, fonts, etc, are the bulk of an APK or IPA. Various tools in the Android and iOS ecosystems can help you understand what’s inside of your APK or IPA.

此外,请务必使用 Flutter 工具创建 APK 或 IPA 的_发布版本_。发布版本的体积通常_远_小于_调试_版本。

Also, be sure to create a release build of your APK or IPA with the Flutter tools. A release build is usually much smaller than a debug build.

如果你想学习更多有关如何发布版本的教程,可以查看 打包和发布到 Android 平台 以及 打包和发布到 iOS 平台

Learn more about creating a release build of your Android app, and creating a release build of your iOS app. Also, check out Measuring your app’s size.

Flutter 应用能在 Chromebook 上运行吗?

Do Flutter apps run on Chromebooks?

我们注意到已经有 Flutter 应用运行在某些 Chromebook 上了。针对在 Chromebook 上运行 Flutter 的情况,我们有进行持续的跟踪,你可以查看 Flutter 运行在 Chromebook 上的问题追踪 来获得相关信息。

We have seen Flutter apps run on some Chromebooks. We are tracking issues related to running Flutter on Chromebooks.



为什么 build() 方法被放在 State 上,而不是 StatefulWidget 上?

Why is the build() method on State, rather than StatefulWidget?

将 Widget 的 build(BuildContext context) 方法放在 State 上,而不是将 Widget build(BuildContext context, State state) 方法放在 StatefulWidget 上,这个策略能让开发者在继承 StatefulWidget 时提供更多的灵活性,你可以在 API 文档中查看 关于 State.build 的讨论

Putting a Widget build(BuildContext context) method on State rather putting a Widget build(BuildContext context, State state) method on StatefulWidget gives developers more flexibility when subclassing StatefulWidget. You can read a more detailed discussion on the API docs for State.build.

Flutter 怎么没有标记语言 (markup language) 和语法?

Where is Flutter’s markup language? Why doesn’t Flutter have a markup syntax?

Flutter 的 UI 由指令式的面向对象语言构建,也就是 Dart。它也是 Flutter 框架的编写语言。Flutter 本身并不包含声明式的标记语言。

Flutter UIs are built with an imperative, object-oriented language (Dart, the same language used to build Flutter’s framework). Flutter doesn’t ship with a declarative markup.

我们发现将 UI 交给代码来动态构建会带来更多的灵活性。比如,我们发现固化的标记语言系统很难表达一个从视觉到行为都完全定制的 widget。

We found that UIs dynamically built with code allow for more flexibility. For example, we have found it difficult for a rigid markup system to express and produce customized widgets with bespoke behaviors.


We have also found that our “code-first” better allows for features like hot reload and dynamic environment adaptations.

从根本上来讲,创造出一种能动态转化成 widget 的语言是可能的,毕竟构建方法说到底也还是代码,他们能做的事情很多,自然也包括将标记语言转化成 widget。

It’s possible to create a custom language that is then converted to widgets on the fly. Because build methods are “just code”, they can do anything, including interpreting markup and turning it into widgets.

我的应用运行时在右上角有一个 Debug 的标识,为什么?

My app has a Debug banner/ribbon in the upper right. Why am I seeing that?

默认情况下,flutter run 指令会使用 debug 编译配置。

By default flutter run command uses the debug build configuration.

Debug 编译配置会在一个 VM (Virtual Machine) 里运行您的 Dart 代码,从而提供更快速的开发操作周期,如 热重载。如果是编译发布版本的话,则会使用 AndroidiOS 标准的工具链。

The debug configuration runs your Dart code in a VM (Virtual Machine) enabling a fast development cycle with hot reload (release builds are compiled using the standard Android and iOS toolchains).

Debug 编译配置也会检查所有的断言 (assert),这会帮助您在开发时更早地发现错误,但这也会加大运行时的开销。您看到的 Debug 标识是告诉您这些检查目前是打开的状态。您可以通过在运行 flutter run 时附加 --profile 或者 --release 来跳过这些检查。

The debug configuration also checks all asserts, which helps you catch errors early during development, but imposes a runtime cost. The “Debug” banner indicates that these checks are enabled. You can run your app without these checks by using either the --profile or --release flag to flutter run.

如果您在使用 Flutter 的 IntelliJ 插件,您可以在 profile 或者 release 模式下启动应用,只需要在菜单里选择 Run > Flutter run in Profile Mode 或者 Release Mode 即可。

If your IDE uses the Flutter plugin, you can launch the app in profile or release mode. For IntelliJ, use the menu entries Run > Flutter Run in Profile Mode or Release Mode.

Flutter 框架采用了哪些编程范式?

What programming paradigm does Flutter’s framework use?

Flutter 是一个多范式的编程环境。过去几十年中许多编程技术都有在 Flutter 中使用。我们在选择范式时会考虑其适用性进行综合性的决策。以下列出的范式不分先后:

Flutter is a multi-paradigm programming environment. Many programming techniques developed over the past few decades are used in Flutter. We use each one where we believe the strengths of the technique make it particularly well-suited. In no particular order:

组合 (composition)
这也是 Flutter 的主要开发范式,将简单的、行为有限的小对象进行组合,从而实现更复杂的效果。绝大多数 Flutter widget 都是用这种方法构建的。比如 Material [FlatButton][] 类是基于 MaterialButton 类构建的,而这个类则是由 IconThemeInkWellPaddingCenterMaterialAnimatedDefaultTextStyle 以及 ConstrainedBox 组合而成的。而 InkWell 则是由 GestureDetector 组成, Material 则是由 AnimatedDefaultTextStyleNotificationListenerAnimatedPhysicalModel 组成。如此等等。

The primary paradigm used by Flutter is that of using small objects with narrow scopes of behavior, composed together to obtain more complicated effects, sometimes called aggressive composition. Most widgets in the Flutter widget library are built in this way. For example, the Material TextButton class is built using an IconTheme, an InkWell, a Padding, a Center, a Material, an AnimatedDefaultTextStyle, and a ConstrainedBox. The InkWell is built using a GestureDetector. The Material is built using an AnimatedDefaultTextStyle, a NotificationListener, and an AnimatedPhysicalModel. And so on. It’s widgets all the way down.

函数式编程 (functional programming)
整个应用都可以只用 StatelessWidget 来构建,它本质上就是一些方法,用来描述如何将参数传送给其他方法,以及在布局区域内计算布局以及绘制图像。当然这样的应用一般也不会包含状态,所以通常也无法进行交互。比如,Icon widget 就只是一个将其元素 (颜色图标尺寸) 罗列在布局区域内的方法。另外,当这个范式被重度使用时,则会使用不可变的数据结构,如整个 Widget 类及其派生,以及一些辅助类,如 RectTextStyle。另外,从一个较小的尺度来看的话, Dart 的 Iterable API 也重度使用了这个范式 (如 map, reduce, where 等方法),它在框架中经常被用来处理一系列的值。

Functional programming
Entire applications can be built with only StatelessWidgets, which are essentially functions that describe how arguments map to other functions, bottoming out in primitives that compute layouts or paint graphics. (Such applications can’t easily have state, so are typically non-interactive.) For example, the Icon widget is essentially a function that maps its arguments (color, icon, size) into layout primitives. Additionally, heavy use is made of immutable data structures, including the entire Widget class hierarchy as well as numerous supporting classes such as Rect and TextStyle. On a smaller scale, Dart’s Iterable API, which makes heavy use of the functional style (map, reduce, where, etc), is frequently used to process lists of values in the framework.

事件驱动编程 (event-driven programming)
用户的交互操作被包装成事件对象,这些对象发送给被各个 event handler 注册的回调方法。屏幕内容的更新使用的也是类似的回调机制。比如,做为动画系统构建基础的 Listenable 类,就采用了包含多个事件监听者的订阅模型。

Event-driven programming
User interactions are represented by event objects that are dispatched to callbacks registered with event handlers. Screen updates are triggered by a similar callback mechanism. The Listenable class, which is used as the basis of the animation system, formalizes a subscription model for events with multiple listeners.

面向类编程 (class-based programming,是面向对象编程的一种方式)
框架内绝大多数的 API 是由包含各种继承关系的类来组成的。我们在基本类中定义较高级别的 API,然后在其子类中对这些 API 进行特化处理。比如,我们的渲染对象就有一个基本类 RenderObject),它对坐标系的细节并不关心,但它的子类 RenderBox) 就引入了笛卡尔坐标系的概念 (x/y坐标值,以及宽度高度的概念)。

Class-based object-oriented programming
Most of the APIs of the framework are built using classes with inheritance. We use an approach whereby we define very high-level APIs in our base classes, then specialize them iteratively in subclasses. For example, our render objects have a base class (RenderObject) that is agnostic regarding the coordinate system, and then we have a subclass (RenderBox) that introduces the opinion that the geometry should be based on the Cartesian coordinate system (x/width and y/height).

原型编程 (prototype-based programming,同样是面向对象编程的一种方式)
ScrollPhysics 类在运行时动态链接那些会组成滚动逻辑的实例。这就使得系统无需在编译时提前选择平台的情况下,也能组合出符合平台特性的页面滚动效果。

Prototype-based object-oriented programming
The ScrollPhysics class chains instances to compose the physics that apply to scrolling dynamically at runtime. This lets the system compose, for example, paging physics with platform-specific physics, without the platform having to be selected at compile time.

指令式编程 (imperative programming)
简单直白的指令式编程,通常和对象内封装的状态 (state) 搭配使用,这种范式能提供最符合直觉的解法。比如,测试就是使用指令式编程实现的,首先描述出测试的环境,然后给出测试需要满足的定量,最后开始步进,或者根据测试需要插入事件。

Imperative programming
Straightforward imperative programming, usually paired with state encapsulated within an object, is used where it provides the most intuitive solution. For example, tests are written in an imperative style, first describing the situation under test, then listing the invariants that the test must match, then advancing the clock or inserting events as necessary for the test.

响应式编程 (reactive programming)
Widget 和元素树有时候被描述为响应式的,因为随 widget 构造方法引入的新输入会随着其 build 方法传播给更低等级的 widget;而底层 widget 中出现的修改 (如响应用户的输入) 也会沿着结构树通过 event handler 向上传播。在整个框架中,函数-响应式以及指令-响应式的实现都有出现,具体取决于 widget 的功能需求。 Widget 的 build 方法如果只是包含其针对变化如何响应的表达式的话,就是函数-响应式 widget (如 Material Divider 类)。如果 widget 的 build 方法包含一系列构造子元素的表达式,用于描述该 widget 如何响应变化的话,那它就是指令响应式 widget (如 Chip 类)。

Reactive programming
The widget and element trees are sometimes described as reactive, because new inputs provided in a widget’s constructor are immediately propagated as changes to lower-level widgets by the widget’s build method, and changes made in the lower widgets (for example, in response to user input) propagate back up the tree via event handlers. Aspects of both functional-reactive and imperative-reactive are present in the framework, depending on the needs of the widgets. Widgets with build methods that consist of just an expression describing how the widget reacts to changes in its configuration are functional reactive widgets (for example, the Material Divider class). Widgets whose build methods construct a list of children over several statements, describing how the widget reacts to changes in its configuration, are imperative reactive widgets (for example, the Chip class).

声明式编程 (declarative programming)
Widget 的 build 方法通常都是一个单一表达式,它包含多级嵌套的构造函数,且使用 Dart 严格的声明式子集编写。这些嵌套的表达式可以与合适的标记语言互相转换。比如,UserAccountsDrawerHeader 这个 widget 就有一个很长的 build 方法 (20 多行),由一个嵌套的表达式构成。这种范式也可以和指令式混合使用,以实现某些很难用纯声明式的方法实现的 UI。

Declarative programming
The build methods of widgets are often a single expression with multiple levels of nested constructors, written using a strictly declarative subset of Dart. Such nested expressions could be mechanically transformed to or from any suitably expressive markup language. For example, the UserAccountsDrawerHeader widget has a long build method (20+ lines), consisting of a single nested expression. This can also be combined with the imperative style to build UIs that would be harder to describe in a pure-declarative approach.

泛型程序设计 (generic programming)
类型可以帮助开发者更早地抓到错误,基于这一点,Flutter 框架也采用了泛型开发。比如,State 类就是如此,其关联的 widget 就是类型参数,如此一来 Dart 分析器就能捕获到 state 和 widget 不匹配的情况。类似的,GlobalKey 类就接受一个类型参数,从而类型安全地访问一个 widget 的 state (会使用运行时检查)。 Route 接口也在被 popped 时接受类型参数,另外 List, Map, Set 这些集合也都如此,这样就可以在分析或者运行时尽早发现类型不匹配的错误。

Generic programming
Types can be used to help developers catch programming errors early. The Flutter framework uses generic programming to help in this regard. For example, the State class is parameterized in terms of the type of its associated widget, so that the Dart analyzer can catch mismatches of states and widgets. Similarly, the GlobalKey class takes a type parameter so that it can access a remote widget’s state in a type-safe manner (using runtime checking), the Route interface is parameterized with the type that it is expected to use when popped, and collections such as Lists, Maps, and Sets are all parameterized so that mismatched elements can be caught early either during analysis or at runtime during debugging.

并发 (concurrent programming)
Flutter 大量使用诸如 Future 等异步 API。比如,动画系统就会在动画执行完 future 时进行事件告知。同样的,图片加载系统也会使用 future 在加载完毕时进行告知。

Concurrent programming
Flutter makes heavy use of Futures and other asynchronous APIs. For example, the animation system reports when an animation is finished by completing a future. The image loading system similarly uses futures to report when a load is complete.

约束编程 (constraint programming)
Flutter 的布局系统使用了约束编程的简化形态来描述一个场景的几何性质。约束值 (比如一个笛卡尔矩形允许的最大 / 最小宽高值) 会从父元素传递给子元素,子元素最终选择一个能满足上面所有约束条件的最终尺寸。这种做法也使得 Flutter 能不依赖太多输入的情况下快速完成一个全新的布局。

Constraint programming
The layout system in Flutter uses a weak form of constraint programming to determine the geometry of a scene. Constraints (for example, for cartesian boxes, a minimum and maximum width and a minimum and maximum height) are passed from parent to child, and the child selects a resulting geometry (for example, for cartesian boxes, a size, specifically a width and a height) that fulfills those constraints. By using this technique, Flutter can usually lay out an entire scene with a single pass.




Where can I get support?

If you think you’ve encountered a bug, file it in our issue tracker. You might also use Stack Overflow for “HOWTO” type questions. For discussions, join our mailing list at flutter-dev@googlegroups.com or seek us out on Discord.

如果您觉得遇到 bug 了,请提交至我们的 问题追踪入口。我们也鼓励您在 Stack Overflow 中多多使用 “如何 (how to) …“来搜索解答。如果您希望直接与我们沟通,请使用我们的官方邮件地址 flutter-dev@googlegroups.com

For more information, see our Community page.

我如何投入到 Flutter 开发社区?

How do I get involved?

Flutter 是开源的,我们鼓励您为此做出自己的贡献。您可以通过 问题追踪入口 来提交功能需求或者 bug 报告。

Flutter is open source, and we encourage you to contribute. You can start by simply filing issues for feature requests and bugs in our issue tracker.

我们也希望您加入我们的邮件讨论 (flutter-dev@googlegroups.com),告诉我们您是如何使用 Flutter 的,以及打算用 Flutter 开发什么。

We recommend that you join our mailing list at flutter-dev@googlegroups.com and let us know how you’re using Flutter and what you’d like to do with it.

如果您打算为 Flutter 贡献代码,请先阅读 代码贡献指南,然后从 简单待修复问题 列表中寻找力所能及的问题开始入手。

If you’re interested in contributing code, you can start by reading our Contributing Guide and check out our list of easy starter issues.

最后,您可以与各个 Flutter 社区保持联系,更多相关信息,请查阅我们的 社区 页面。

Finally, you can connect with helpful Flutter communities. For more information, see our Community page.

Flutter 是开源的吗?

Is Flutter open source?

是的,Flutter 是开源的。您可以在 GitHub 上获取到它。

Yes, Flutter is open source technology. You can find the project on GitHub.

Flutter 以及其依存项目使用的是哪种软件许可协议?

Which software license(s) apply to Flutter and its dependencies?

Flutter 包含两个部分:一个使用动态链接二进制文件发行的引擎,以及引擎加载的 Dart 框架二进制文件。引擎使用了很多软件组件,且包含许多依存内容。完整的说明和依存清单请查看引擎的 许可协议

Flutter includes two components: an engine that ships as a dynamically linked binary, and the Dart framework as a separate binary that the engine loads. The engine uses multiple software components with many dependencies; view the complete list in its license file.

框架部分则自成一体,且 只有一份简单的许可协议

The framework is entirely self-contained and requires only one license.

另外,您使用的其他 Dart 代码包可能有其独有的许可协议。

In addition, any Dart packages you use might have their own license requirements.

我如何确定我的 Flutter 应用该显示哪些许可协议?

How can I determine the licenses my Flutter application needs to show?

您可以使用 API 来确定需要显示的许可协议。

There’s an API to find the list of licenses you need to show:

目前有哪些人在开发 Flutter?

Who works on Flutter?

我们都在参与 Flutter 开发!我们都知道 Flutter 是一个开源项目。目前 Flutter 中的大部分都是由 Google 的工程师来开发。如果您喜欢 Flutter 的话,我们希望您加入开发者社区并做出贡献!

We all do! Flutter is an open source project. Currently, the bulk of the development is done by engineers at Google. If you’re excited about Flutter, we encourage you to join the community and [contribute to Flutter][]!

Flutter 有哪些指导原则?

What are Flutter’s guiding principles?


We believe that:

  • 为了触达每一位潜在用户,开发者需要针对多个移动平台发布自己的应用。

    In order to reach every potential user, developers need to target multiple mobile platforms.

  • 目前常用的 HTML 和 WebView 由于一些默认的交互响应 (滚动、布局等) 以及向后兼容等问题,很难获得稳定的高帧率和精确的设计体验。

    HTML and WebViews as they exist today make it challenging to consistently hit high frame rates and deliver high-fidelity experiences, due to automatic behavior (scrolling, layout) and legacy support.

  • 目前,开发同一个应用的不同平台版本成本很高:这意味着不同的团队、不同的代码库、不同的工作流程以及不同的工具,等等。

    Today, it’s too costly to build the same app multiple times: it requires different teams, different code bases, different workflows, different tools, etc.

  • 开发者需要一个简单的、更好的方法来使用同一套代码库开发应用的不同平台版本。而且他们不希望在质量、细节和功能控制以及性能上有任何妥协。

    Developers want an easier, better way to use a single codebase to build mobile apps for multiple target platforms, and they don’t want to sacrifice quality, control, or performance.


We are focused on three things:

Developers deserve access to, and control over, all layers of the system. Which leads to:



Users deserve perfectly fluid, responsive, jank-free apps. Which leads to:


Everyone deserves precise, beautiful, delightful app experiences.

Apple 会拒绝我的 Flutter 应用吗?

Will Apple reject my Flutter app?

我们无法代 Apple 发言,但已经有很多使用类似 Flutter 的其他技术开发的应用。实际上,Flutter 与 Unity 使用了近乎一致的底层架构模型,Apple store 中最著名的游戏也是使用它的引擎开发的。

We can’t speak for Apple, but their App Store contains many apps built with framework technologies such as Flutter. Indeed, Flutter uses the same fundamental architectural model as Unity, the engine that powers many of the most popular games on the Apple store.

Apple 最近评选的最佳设计应用也是使用 Flutter 开发的,其中包括 Hamilton]Hamilton for iOS 和 [Reflectly][]。

Apple has frequently featured well-designed apps that are built with Flutter, including Hamilton and [Reflectly][].

任何提交到 Apple store 的 Flutter 应用都应该遵守 Apple 的 [规范][guidelines]。

As with any app submitted to the Apple store, apps built with Flutter should follow Apple’s [guidelines][] for App Store submission.