title | short-title | description |
---|---|---|
Dart FAQ |
FAQ |
You have questions about Dart, we have answers. |
{% assign pdf = 'picture_as_pdf' %} {% assign site-repo = site.repo.this %} {% assign sdk-repo = site.repo.dart.sdk %} {% assign lang-repo = site.repo.dart.lang %} {% assign ecma-pdf = 'https://ecma-international.org/wp-content/uploads' %}
This page collects some of the top questions from the community.
Yes. EMCA-408 covers the Dart Programming Language Specification.
Five versions have been published. The latest in-progress version covers to Dart 2.13-dev.
Edition | Published | Approved | Covers to version |
---|---|---|---|
6th {{pdf}} | January 24, 2024 | 2.13-dev | |
5th {{pdf}} | April 9, 2021 | 2.10 | |
4th {{pdf}} | August 19, 2015 | December 2015 | 1.11 |
3rd {{pdf}} | April 15, 2015 | June 2015 | 1.9 |
2nd {{pdf}} | November 21, 2014 | December 2014 | 1.6 |
1st {{pdf}} | March 27, 2014 | June 2014 | 1.3 |
{:.table .table-striped}
To learn more about the specification, review the Dart language specification page.
The team listens to feedback, reads issues, and reviews patches from contributors. A contributor with a good track record can be granted write permission to the repository. Google engineers also work in the public repository, making visible changes. The project has received many external patches and welcomes distributed committers.
Dart has some similarities with Java. To review brief examples with familiar syntax, reviewed the code samples in the Introduction to Dart.
Google started the Dart and Go language projects. These independent projects have different goals. As a result, they make different choices. The languages have very different natures, but team members learn from each others' work.
Various reasons that depend on the comparison language.
Languages differ from JavaScript : Dart must compile to efficient JavaScript. Source languages that differ too much from JavaScript can generate complex output code to emulate the source language's behavior. This can cause performance to vary in non-obvious ways to the programmer.
Languages that compile to native code : Dart prioritizes efficient compilation to machine code. Therefore, it shares some aspects with other compiled languages.
Languages that are considered "more dynamic" than Dart : Dart chooses to trade off some of this arbitrary runtime modification to achieve better performance and more productive tools.
Some nice syntactic features exist, like the this.
constructor args and =>
for one-line functions.
Dart chooses familiarity over excitement.
Servers and command-line scripts : Yes, Dart supports reflection from the mirrors API.
Web or Flutter apps : No, Dart doesn't support write to web or Flutter apps.
Future releases might include a feature you want. Some features don't fit the nature of the language. Some don't play well with other features. Simplicity is the most important gift to give to future programmers.
To check if someone has filed your request, review the language funnel and language issues list.
-
If an issue exists, add your thumbs up.
-
If an issue doesn't exist, request a new issue.
Make a thoughtful argument for your feature. Add evidence to your argument. Include sample code with and without your feature or a sizeable codebase.
To learn more, consult the language evolution process.
Don't be surprised if the Dart language team turns down your request. Removing a language feature inflicts more pain than adding one. The Dart language team adds the most obvious features first, and revisits the next tier later.
The community will request more features than any single language can meet without making a total hash of it. The Dart language team does appreciate suggestions and evidence. This appreciation should become apparent through careful design choices and fair communication about them.
Yes, Dart uses static typing. To learn more, consult Dart's type system.
Combining static and runtime checks, Dart has a sound type system. This guarantees that an expression of one type cannot produce a value of another type.
if you need the flexibility of a dynamic typing,
you can annotate any variable with dynamic
.
This dynamic
type is static, but can contain any type at runtime.
That removes many benefits of a type-safe language from that variable.
Covariant generics fit a common intuition that programmers have, and very often this intuition is correct, such as in the common "read-only" use of a generic. Although this intuition isn't always correct, Dart is erring on the side of convenience by having covariant generics.
The only other reasonable default variance would be invariance. While having only invariant generics would definitely prevent more errors, it would also prevent a lot of valid programs or require conversion every time you have a list of "apples", and someone just wants "fruits".
We are familiar with a variety of ways that languages try to mark or infer variance. We feel that variance inference systems add too much complexity for their benefit in Dart.
Again, we're trying to be pragmatic, and we think the outcome is reasonable.
Yes. To learn more, consult the JSON converters in the dart:convert library.
Yes. To learn more, consult Dart on the Server.
Search for packages on the pub.dev site,
the package-hosting service for Dart and Flutter.
Use the pub
command to package your code and upload to the site.
No. You can try out Dart code with DartPad, and then use your favorite editor or IDE for development. Some full-featured IDEs such as IntelliJ IDEA, WebStorm, and Visual Studio Code have Dart plugins. Open source Dart plugins also exist for a number of editors. For more information, see the Dart tools.
Yes! You can build an Android app using the Flutter framework and the Dart language. Any Flutter app you write will also work on iOS, the web, and desktop platforms.
Google Ads, AdSense, AdMob, and the Google Assistant use Dart. A significant portion of Google's revenue flows through these apps. Inside or outside of Google, every Flutter app uses Dart.
No. On native targets, Dart's isolate API can start multiple execution threads when needed. The Dart VM uses multiple CPU cores to run those threads at the same time.
Dart's concurrency architecture abstracts the complex, error-prone code of typical shared-memory threading. This might explain the misconception that Dart is single-threaded.
Concurrency works differently in Dart web apps. To learn more, consult Is Dart single-threaded on the web?
Yes. When compiling apps that target devices like desktops or mobile, Dart Native includes both a Dart VM with a just-in-time (JIT) compiler and an ahead-of-time (AOT) compiler to produce native code.
The Flutter framework uses Dart's native compilation capability to produce fast native apps.
Yes. Dart programs can be compiled to native code for running in a macOS Terminal, Windows command prompt, or a Linux shell.
Consult the dart compile documentation.
It depends. How Dart compiles code produces apps with different performance characteristics.
-
AOT-compiled code starts fast with consistent runtime performance, with no latency during early runs.
-
JIT-compiled code starts slower, but reaches peak performance after it runs long enough to apply runtime optimizations.
The production web compiler supports the last two major releases of the following browsers:
- Google Chrome
- Microsoft Edge
- Firefox
- Apple Safari
The development JavaScript compiler only supports Chrome for debugging.
Somewhat. Dart web apps can't use isolates. To achieve code concurrency, web apps use web workers. Web workers lack the ease and efficiency of isolates, and have different capabilities and restrictions. To learn more, consult Concurrency on the web.
Any valid Dart code should compile to JavaScript.
Some libraries run only on the server or in Flutter.
Consider the dart:io
library.
It provides access to operating system files
and directories with APIs not available to the browser.
Both ways use the webdev
command.
The webdev build
command produces minified JavaScript optimized for
production.
The webdev serve
command produces modularized JavaScript optimized for
debugging.
To learn more, consult the Dart JavaScript compiler reference
JavaScript has only one number representation: an IEEE-754 double-precision floating-point number. This means that any number—integer or floating point—is represented as a double. JavaScript has typed data arrays, and the mapping from native Dart typed lists to JavaScript typed arrays is trivial.
JavaScript stores all numbers as doubles. This limits integers to 53-bit precision with values ranging from -253 to 253 JavaScript can store integers in this range without loss of accuracy. As JavaScript VMs manipulates the internal representation of numbers, stay within the small integer (SMI) range. In JavaScript, that range falls between -231 to 231 (-2,147,483,647 to 2,147,483,648 including 0).
JavaScript offers 32-bit typed arrays compatible with Dart's typed lists.
This maps as Float32List
becoming a Float32Array
.
The production JavaScript compiler doesn't support 64-bit integers:
Int64List
or Uint64List
. Compiling Dart code with
either of those lists results in a runtime exception.