In the previous tutorial, Flutter was developed using the Dart language. This tutorial provides an overview of the Dart language. Note that Dart VM and Dart 2JS are not covered in this tutorial because they have nothing to do with Flutter. This paper will introduce Dart language features, ecology and future from the perspective of Flutter development.

Note: If you want to quickly learn about Dart to develop Flutter, Flutter Chinese has a list of resources for the Dart language. Read them in order to get you started.

Dart language features

First let’s take a look at why Flutter chose Dart as its development language. Here are the official reasons:

Flutter was evaluated across four main dimensions, taking into account factors such as the needs of framework authors, developers and end users. We found that different languages met some of the requirements at different levels, but Dart scored highly on all of the evaluation dimensions and met all of our requirements and criteria.

The Dart runtime and compiler support a combination of two key features of Flutter: rapid JIT based development cycles that allow shape changes and stateful thermal overloading using type-based languages; And an AOT compiler that generates efficient ARM code that can be started quickly and has predictable production deployment performance.

In addition, we have the opportunity to work closely with the Dart community, which is actively investing resources to improve Dart use in Flutter. For example, when we adopted Dart, the language didn’t provide a toolchain to generate native binaries (which would be helpful for achieving predictable performance), but now it does, because the Dart team built it for Flutter. Similarly, the Dart VM was previously optimized for throughput, but the team is now optimizing the VM’s latency time, which is more important for the Flutter workload.

Dart gets high marks on the following key criteria:

  • Developer productivity. One of Flutter’s main value propositions is that it saves engineering resources by letting developers create apps for iOS and Android using the same code base. Using an efficient language can further speed up the development cycle and make Flutter more attractive. This is very important for both our Framework team and our developers. Most of Flutter functionality is implemented using Dart, so we need to be efficient at 100,000 lines of code without sacrificing the readability of the framework and widgets.
  • Object oriented. We could use a non-object-oriented language, but that would mean reworking several difficult issues. In addition, most developers have experience with object-oriented development, so it is easier to learn how to develop with Flutter.
  • Predictable, high performance. With Flutter, we want to enable developers to quickly create a fluid user experience. To do this, we need to be able to run a lot of code in each animation frame. This means that we need a language that provides both high performance and predictable performance without periodic pauses that result in frame loss.
  • Fast memory allocation. The Flutter framework uses functional streams, which rely heavily on the underlying memory allocator. It is important to handle small, short-term memory allocations efficiently, so Flutter cannot work effectively in languages that lack this functionality.

To sum up, the main message is that Dart has no VM in flutter, can compile native code directly with the AOT compiler, and memory management is suitable for flutter. My use of Dart suggests that Dart should be designed to be both Java and Javascript compliant.

Dart vs Java

Dart VM has been optimized for memory recovery and throughput. However, I have not found specific performance comparisons. However, in my opinion, as long as Dart language is popular, There is no need to worry about vm performance. After all, Google has made a lot of achievements in GO (no VM but GC), javascript (V8) and Dalvik (Java VM on Android). It is worth noting that Dart has been able to achieve GC within 10ms in flutter. Dart is much more expressive than Java at the syntactic level. Most importantly, Dart’s support for functional programming is much better than Java’s (currently lamda expressions). Dart’s lack of ecology is discussed below.

Dart vs JavaScript

JavaScript’s weak typing has long been short, so typeScript, Coffeescript, and even Facebook’s Flow (which is not a superset of JavaScript, but also provides static type checking through annotation and packaging tools) are in the market. In fact, in my opinion, the most powerful and dynamic scripting language is javascript, which supports dynamic extension of properties, creation of functions, etc., which is super cool to use. But you’ve probably heard that javascript’s powerful dynamics are a double-edged sword. After all, some people are always nervous about their code, and they expect a system of static type checking to help reduce errors. Dart has static type checking (dynamic type checking was added after Dart2.0, Dart is similar to typeScript and Coffeescript in this sense, so in isolation, Dart doesn’t have an obvious advantage over typeScript and Coffeescript, but the combination of server-side scripting, APP development, and Web development gives Dart an advantage.

Flutter in the Dart

Flutter can run most DART code that does not directly or indirectly import DART :mirrors or DART: HTML. Dart code in Flutter is compiled into native code by the AOT compiler, without vm, and the DART team has optimized Flutter specifically.

The Dart ecological

The success or failure of a language depends on its ecology. There are two main indicators of the ecosystem: the number of third-party libraries and the number of developers.

Dart third-party libraries are still few and of low quality. Even for Dart SDK, there are many bugs in it. The open issue of Dart-SDK Github has been around 5000. Dart is still not perfect. Fortunately, Dart is currently iterating much faster, thanks to flutter and Fuchsia.

As for developers, the majority of DART users are CURRENTLY FLUTTER users. There should be very few server scripts written with DART, since there is no well-known or time-proven Web Server framework in the Dart community. Based on dart related issues on StackOverflow, there are a few developers developing JS with DART, but it’s estimated to be no more than 20% of DART developers.

Flutter Chinese community contribution

Flutter Chinese has launched an open source project plan, aiming to develop a series of common (practical) packages and plug-ins in addition to the Flutter SDK, in order to enrich the third-party Flutter library and contribute to the Flutter ecosystem from Chinese developers. At present, several open source projects have been launched in the community. More details about Flutter Chinese open Source Project: Flutter Chinese open Source Project (ps: Flutter Chinese open Source project is currently looking for strong, ambitious and passionate developers to join Flutter Chinese open Source project. If you are interested, click here to get your contact information).

The Dart in the future

The Dart ecosystem isn’t perfect yet, but it’s growing fast. More than five new packages are released every day on the PUB, which you might not think is true, but the most commonly used packages in Java are around 200. The Dart language has its own strengths, but there are mature and decent solutions for its target areas, so I think the success of Dart will depend on the success of Flutter and Fuchsia for now.

Flutter currently has nearly 23K star on Github without the first official release, which is quite popular (certainly not compared to the 100K star of front-end Web frameworks like Vue, which have different developer communities and open source dates). From the perspective of Flutter itself, the developed application performance is indeed much smoother, significantly better than WEEX and RN.

Also, DART and Flutter have become first-class citizens with the release of Google’s Fuchsia OS, meaning DART will become the primary development language for all future devices with Fuchsia OS.

The last

Some resources:

  1. For a tutorial on Flutter resources, visit Flutter Chinese website.
  2. The Flutter HTTP request library DIO.
  3. Flutter tutorial