Dart (programming language)#Example

{{Short description|Programming language}}

{{About|a programming language|the advertising application formerly named Google Dart|DoubleClick for Publishers by Google|other uses|Dart (disambiguation){{!}}Dart}}

{{Infobox programming language

| name=

| title=Dart

| logo=Dart programming language logo.svg

| logo caption=

| screenshot=

| screenshot caption=

| paradigm=Multi-paradigm: functional, imperative, object-oriented, reflective{{cite book|last1=Kopec|first1=David|title=Dart for Absolute Beginners|date=30 June 2014|isbn=9781430264828|page=56|publisher=Apress |url=https://books.google.com/books?id=EcvjAwAAQBAJ&q=dart%20multi-paradigm&pg=PA56|access-date=24 November 2015}}

| family=

| released={{Start date and age|2011|10|10}}{{cite web|last1=Bak|first1=Lars|title=Dart: a language for structured web programming|url=http://googlecode.blogspot.com/2011/10/dart-language-for-structured-web.html|website=Google Code Blog|date=10 October 2011|access-date=31 January 2016}}

| designer=Lars Bak, Kasper Lund

| developer=Google

| latest release version={{Wikidata|property|reference|edit|Q406009|P348}}

| latest release date={{start date and age|

{{wikidata|qualifier|single|P548=Q2804309|P348|P577}}}}

| latest preview date={{Start date and age|2021|12|14}}{{Cite web|url=https://github.com/dart-lang/sdk/tags|title=Dart SDK Tags|website=GitHub }}

| typing=1.x: Optional
2.x: Inferred{{Cite web|url=https://dart.dev/guides/language/sound-dart|title=The Dart type system|website=dart.dev}} (static, strong)

| scope=

| implementations=Dart VM, dart2native, dart2js, DDC, Flutter

| dialects=

| influenced by=C, C++, C#, Erlang, Java, JavaScript, Ruby, Smalltalk, Strongtalk,{{cite web|title=Web Languages and VMs: Fast Code is Always in Fashion. (V8, Dart) - Google I/O 2013|website=YouTube|date=16 May 2013 |url=https://www.youtube.com/watch?v=huawCRlo9H4&t=30m10s|access-date=22 December 2013}} TypeScript{{cite web|title=The Dart Team Welcomes TypeScript|date=10 September 2019 |url=https://news.dartlang.org/2012/10/the-dart-team-welcomes-typescript.html|access-date=22 February 2020}}

| influenced=

| programming language=

| platform=Cross-platform

| operating system=Cross-platform

| license=BSD

| website={{URL|dart.dev}}

| file ext=.dart

| fileformat=

}}

Dart is a programming language designed by Lars Bak and Kasper Lund and developed by Google.{{Cite web |title=A Bit About Dart - Learn Dart: First Step to Flutter |url=https://www.educative.io/courses/learn-dart-first-step-to-flutter/g7kmn5r74ok |access-date=2023-06-20 |website=Educative: Interactive Courses for Software Developers |language=en}} It can be used to develop web and mobile apps as well as server and desktop applications.

Dart is an object-oriented, class-based, garbage-collected language with C-style syntax.{{Cite web|url=https://dart.dev/guides/language/language-tour#important-concepts|title=A Tour of the Dart Language|website=dart.dev|access-date=2018-08-09}} It can compile to machine code, JavaScript, or WebAssembly. It supports interfaces, mixins, abstract classes, reified generics and type inference.{{Cite web|url=https://dart.dev/guides/language/sound-dart|title=The Dart type system|website=dart.dev}}

History

Dart was unveiled at the GOTO conference in Aarhus, Denmark, October 10–12, 2011.{{Citation |contribution-url=http://gotocon.com/aarhus-2011/presentation/Opening%20Keynote:%20Dart,%20a%20new%20programming%20language%20for%20structured%20web%20programming |format=presentation |type=opening keynote |contribution=Dart, a new programming language for structured web programming |title=GOTO conference |url=http://gotocon.com/aarhus-2011/ |place=Århus conference |date=2011-10-10}} Lars Bak and Kasper Lund founded the project.{{cite web|url=http://radar.oreilly.com/2012/03/what-is-dart.html|title=What is Dart |website=What is Dart? |last=Ladd |first=Seth |publisher=O'Reilly |access-date=August 16, 2014}} Dart 1.0 was released on November 14, 2013.{{Cite web|url=https://news.dartlang.org/2013/11/dart-10-stable-sdk-for-structured-web.html|title=Dart 1.0: A stable SDK for structured web apps|website=news.dartlang.org|access-date=2018-08-08}}

Dart had a mixed reception at first. Some criticized the Dart initiative for fragmenting the web because of plans to include a Dart VM in Chrome. Those plans were dropped in 2015 with the Dart 1.9 release. Focus changed to compiling Dart code to JavaScript.{{cite web|url=http://news.dartlang.org/2015/03/dart-for-entire-web.html|title=Dart News & Updates|author=Seth Ladd|work=dartlang.org|date=10 September 2019 }}

Dart 2.0 was released in August 2018 with language changes including a type system.{{Cite web|url=https://medium.com/dartlang/dart-2-stable-and-the-dart-web-platform-3775d5f8eac7|title=Announcing Dart 2 Stable and the Dart Web Platform|last=Moore|first=Kevin|date=2018-08-07|website=Dart|access-date=2018-08-08}}

Dart 2.6 introduced a new extension, dart2native. This extended native compilation to the Linux, macOS, and Windows desktop platforms.{{Cite web |title=Dart language evolution |url=https://dart.dev/guides/language/evolution |access-date=2023-06-20 |website=dart.dev |language=en}} Earlier developers could create new tools using only Android or iOS devices. With this extension, developers could deploy a program into self-contained executables. The Dart SDK doesn't need to be installed to run these self-contained executables.{{Cite web |title=Dart overview |url=https://dart.dev/overview.html |access-date=2023-05-12 |website=dart.dev |language=en }}{{Dead link|date=March 2024 |bot=InternetArchiveBot |fix-attempted=yes }} The Flutter toolkit integrates Dart, so it can compile on small services like backend support.{{Cite web|url=https://www.infoworld.com/article/3454623/dart-26-brings-native-compilation-to-the-desktop.html|title=Dart 2.5 brings native compilation to the desktop|website=Infoworld|date=20 November 2019|access-date=2019-11-28}}{{Cite web|url=https://sdtimes.com/goog/dart-2-6-released-with-dart2native/|title=Dart 2.6 released with dart2native|website=SDtimes|date=7 November 2019|access-date=2019-11-28}}

Dart 3.0 was released in May 2023{{Cite web |title=Dart language evolution |url=https://dart.dev/guides/language/evolution |access-date=2024-01-09 |website=dart.dev |language=en}} with changes to the type system to require sound null safety. This release included new features like records, patterns,{{Cite web |title=Patterns |url=https://dart.dev/language/patterns.html |access-date=2023-05-12 |website=dart.dev |language=en }}{{Dead link|date=March 2024 |bot=InternetArchiveBot |fix-attempted=yes }} and class modifiers.{{Cite web |title=Class modifiers |url=https://dart.dev/language/class-modifiers}}

Dart can compile to WebAssembly since version 3.4.{{Cite web |last=Thomsen |first=Michael |date=2024-05-14 |title=Landing Flutter 3.22 and Dart 3.4 at Google I/O 2024 |url=https://medium.com/flutter/io24-5e211f708a37 |access-date=2024-05-17 |website=Flutter |language=en}}

Specification

Dart released the 5th edition of its language specification on April 9, 2021.{{Cite web |title=Dart Programming Language Specification, 5th edition |url=https://dart.dev/guides/language/specifications/DartLangSpec-v2.10.pdf}} This covers all syntax through Dart 2.10. A draft of the 6th edition includes all syntax through 2.13.{{Cite web |title=Dart Programming Language Specification, 6th edition draft |url=https://spec.dart.dev/DartLangSpecDraft.pdf}} [https://github.com/dart-lang/language/tree/main/accepted Accepted proposals] for the specification and [https://github.com/dart-lang/language/tree/main/working drafts of potential features] can be found in the Dart language repository on GitHub.{{Cite web |title=Dart language GitHub repository |website=GitHub |url=https://github.com/dart-lang/language}}

ECMA International formed technical committee, TC52,{{cite web |url=http://www.ecma-international.org/memento/TC52.htm |title=TC52 - Dart |access-date=2013-12-16 |archive-url=https://web.archive.org/web/20160802100651/http://www.ecma-international.org/memento/TC52.htm |archive-date=2016-08-02 |url-status=dead }} to standardize Dart. ECMA approved the first edition of the Dart language specification as ECMA-408{{Cite web |title=ECMA-408 |url=https://www.ecma-international.org/publications-and-standards/standards/ecma-408/ |access-date=2023-05-12 |website=Ecma International |language=en-US}} in July 2014 at its 107th General Assembly.{{cite web|url=http://news.dartlang.org/2014/07/ecma-approves-1st-edition-of-dart.html|title=Dart News & Updates|author=Anders Thorhauge Sandholm|work=dartlang.org|date=10 September 2019 }} Subsequent editions were approved in December 2014,{{cite web|url=http://news.dartlang.org/2014/12/enums-and-async-primitives-in-dart.html|title=Dart News & Updates|author=Anders Thorhauge Sandholm|work=dartlang.org|date=10 September 2019 }} June 2015, and December 2015.

Deploying apps

The Dart software development kit (SDK) ships with a standalone Dart runtime. This allows Dart code to run in a command-line interface environment. The SDK includes tools to compile and package Dart apps.{{Cite web |title=Packages of publisher tools.dart.dev |url=https://pub.dev/publishers/tools.dart.dev/packages |access-date=2023-05-12 |website=Dart packages |language=en-us}} Dart ships with a complete standard library allowing users to write fully working system apps like custom web servers.{{cite web |title=An Introduction to the dart:io Library |url=https://dart.dev/guides/libraries/library-tour#dartio |access-date=2013-07-21 |website=dart.dev}}

Developers can deploy Dart apps in six ways:

class="wikitable sortable"

|+Dart deployment methods

!Deployment type

!Target platform

!Platform-
specific

!Requires
Dart VM

!Compile
speed

!Execution
speed

JavaScript

|Browser

|No

|No

|Slow

|Fast

WebAssembly{{Cite web |last=Thomsen |first=Michael |date=2023-05-10 |title=Announcing Dart 3 |url=https://medium.com/dartlang/announcing-dart-3-53f065a10635 |access-date=2023-05-13 |website=Dart |language=en}}

|Browser

|No

|No

|Slow

|Fast

Self-contained executable

|macOS, Windows, Linux

|Yes

|No

|Slow

|Fast

Ahead-of-time module

|macOS, Windows, Linux

|Yes

|No

|Slow

|Fast

Just-in-time module

|macOS, Windows, Linux

|Yes

|Yes

|Fast

|Slow

Portable module

|macOS, Windows, Linux

|No

|Yes

|Fast

|Slow

= Deploying to the web =

Dart 3 can deploy apps to the web as either JavaScript or WebAssembly apps. Dart supports compiling to WebAssembly {{as of|2024|May|lc=y}}.

== JavaScript ==

: To run in mainstream web browsers, Dart relies on a source-to-source compiler to JavaScript. This makes Dart apps compatible with all major browsers. Dart optimizes the compiled JavaScript output to avoid expensive checks and operations. This results in JavaScript code that can run faster than equivalent code handwritten in plain JavaScript.{{cite web |url=http://www.dartlang.org/slides/2012/10/jsconfeu/javascript-as-compilation-target-florian-loitsch.pdf |title=JavaScript as a compilation target: Making it fast |publisher=Dartlang.org |access-date=2013-08-18 |archive-url=https://web.archive.org/web/20160702204820/http://www.dartlang.org/slides/2012/10/jsconfeu/javascript-as-compilation-target-florian-loitsch.pdf |archive-date=2016-07-02}}

: The first Dart-to-JavaScript compiler was dartc. It was deprecated in Dart 2.0.

:The second Dart-to-JavaScript compiler was frog.{{Cite web |title=Towards a single Dart to JavaScript compiler |date=10 September 2019 |url=https://news.dartlang.org/2012/02/towards-single-dart-to-javascript.html |access-date=2023-05-13 |language=en}} Written in Dart, it was introduced in 2013 and deprecated in 2020. This should not be confused with Dart Frog,{{Cite web |title=Dart Frog |url=https://dartfrog.vgv.dev/ |access-date=2023-05-13 |website=dartfrog.vgv.dev |language=en}} an open-source Dart framework for building backend systems from Very Good Ventures.

:The third Dart-to-JavaScript compiler is dart2js. Introduced in Dart 2.0,{{Cite web |last=Moore |first=Kevin |date=2018-08-08 |title=Announcing Dart 2 Stable and the Dart Web Platform |url=https://medium.com/dartlang/dart-2-stable-and-the-dart-web-platform-3775d5f8eac7 |access-date=2023-05-13 |website=Dart |language=en}} the Dart-based dart2js evolved from earlier compilers. It intended to implement the full Dart language specification and semantics. Developers use this compiler for production builds. It compiles to minified JavaScript.

:The fourth Dart-to-JavaScript compiler is dartdevc.{{Cite web |title=dartdevc: The Dart development compiler |url=https://dart.dev/tools/dartdevc.html |access-date=2023-05-13 |website=dart.dev |language=en }}{{Dead link|date=April 2024 |bot=InternetArchiveBot |fix-attempted=yes }} Developers could use this compiler for development builds. It compiles to human-readable JavaScript. On March 28, 2013, the Dart team posted an update on their blog addressing Dart code compiled to JavaScript with the dart2js compiler,{{cite web |last=Ladd |first=Seth |date=2013-03-28 |title=Dart News & Updates: Why dart2js produces faster JavaScript code from Dart |url=http://news.dartlang.org/2013/03/why-dart2js-produces-faster-javascript.html |access-date=2013-07-21 |website=News.dartlang.org.}} stating that it now runs faster than handwritten JavaScript on Chrome's V8 JavaScript engine for the DeltaBlue benchmark.{{cite web |title=Dart Performance |url=http://www.dartlang.org/performance/ |url-status=dead |archive-url=https://web.archive.org/web/20170103041945/http://www.dartlang.org/performance/ |archive-date=2017-01-03 |access-date=2013-07-21 |website=Dartlang.org.}}

:Prior to Dart 2.18, both dart2js and dartdevc could be called from the command line. Dart 2.18 folded these functions into the Dart SDK. This removed the direct command line wrappers but kept the two compilers. The webdev serve command calls the dartdevc compiler. The webdev build command calls the dart2js compiler.

:The Dart SDK compiles to JavaScript in two ways.

:To debug code, run webdev serve to compile a larger JavaScript file with human-readable code. Dart-generated JavaScript can be debugged using Chrome only.

$ cd

$ webdev serve [--debug] [-o ]

To create production apps, run webdev build to compile a minified JavaScript file.

$ cd

$ webdev build [-o ]

== WebAssembly ==

:With the Dart 3.22 release, Google announced support for compiling Dart code to WebAssembly. Full support for Wasm requires adoption of the WasmGC{{Citation |title=GC Proposal for WebAssembly |date=2023-05-12 |url=https://github.com/WebAssembly/gc/blob/5431d631547c8af09a6377e29fee5126219f33c5/proposals/gc/Overview.md |access-date=2023-05-13 |publisher=WebAssembly}} feature into the Wasm standard. Chrome 119{{Cite web |title=WebAssembly Garbage Collection (WasmGC) now enabled by default in Chrome {{!}} Blog |url=https://developer.chrome.com/blog/wasmgc |access-date=2024-05-17 |website=Chrome for Developers |language=en}} supports WasmGC. Firefox{{Cite web |date=2023-02-16 |title=SpiderMonkey Newsletter (Firefox 110-111) |url=https://spidermonkey.dev/blog/2023/02/16/newsletter-firefox-110-111.html |access-date=2023-05-13 |website=SpiderMonkey JavaScript/WebAssembly Engine |language=en-US}} 120 and later could support WasmGC, but a current bug is blocking compatibility.{{Cite web |title=1788206 - OffscreenCanvas.transferToImageBitmap incurs a copy |url=https://bugzilla.mozilla.org/show_bug.cgi?id=1788206 |access-date=2024-05-17 |website=bugzilla.mozilla.org |language=en}} Safari{{Cite web |title=Safari Technology Preview 167 Release Notes |url=https://docs.developer.apple.com/documentation/safari-technology-preview-release-notes/stp-release-167 |access-date=2023-05-13 |website=Apple Developer Documentation |language=en}} and Microsoft Edge are integrating WasmGC support.

= Deploying to native platforms =

Dart can compile to native machine code for macOS, Windows, and Linux as command line tools. Dart can compile apps with user interfaces to the web, iOS, Android, macOS, Windows, and Linux using the Flutter framework.

== Self-contained executable ==

:Self-contained executables include native machine code compiled from the specified Dart code file, its dependencies, and a small Dart runtime. The runtime handles type checking and garbage collection. The compiler produces output specific to the architecture on which the developer compiled it. This file can be distributed as any other native executable.

$ dart compile exe -o

Generated:

$ ./

== Ahead-of-time module ==

:When compiled ahead of time,{{Cite web |last=Obinna |first=Onuoha |date=2020-04-07 |title=How does JIT and AOT work in Dart? |url=https://onuoha.medium.com/how-does-jit-and-aot-work-in-dart-cab2f31d9cb5 |access-date=2023-06-20 |website=Medium |language=en}} Dart code produces performant and platform-specific modules. It includes all dependent libraries and packages the app needs. This increases its compilation time. The compiler outputs an app specific to the architecture on which it was compiled.

$ dart compile aot-snapshot

Generated

$ dartaotruntime

== Just-in-time module ==

:When compiled just in time, Dart code produces performant modules that compile fast. This module needs the Dart VM included with the SDK to run. The compiler loads all parsed classes and compiled code into memory the first time the app runs. This speeds up any subsequent run of the app. The compiler outputs an app specific to the architecture on which it was compiled.

$ dart compile jit-snapshot

Compiling to jit-snapshot file

Hello world!

$ dart run

Hello world!

== Dart kernel module ==

:When compiled as a kernel module, Dart code produces a machine-independent format called the Dart Intermediate Representation (Dart IR). The Dart IR bytecode format can work on any architecture that has a Dart VM. This makes this format very portable and quick to compile, but less performant than other compilation outputs.

$ dart compile kernel

Compiling to kernel file .dill.

$ dart run .dill

Concurrency

To achieve concurrency, Dart uses isolated, independent workers that do not share memory, but use message passing,{{Cite web|title=The Essence of Google Dart: Building Applications, Snapshots, Isolates|url=https://www.infoq.com/articles/google-dart/|access-date=2021-08-29|website=InfoQ|language=en}} similarly to Erlang processes (also see actor model). Every Dart program uses at least one isolate, which is the main isolate. Since Dart 2, the Dart web platform no longer supports isolates, and suggests developers use Web Workers instead.{{Cite web|url=https://groups.google.com/a/dartlang.org/d/msg/misc/djfFMNCWmkE/F7WE8a0JAwAJ|title=Dart2 Breaking Change: Removing web support for dart:mirrors and dart:isolate|last=Moore|first=Kevin|date=February 23, 2018|website=Google Groups}}

Null safety

Starting with Dart 2.12, Dart introduced sound null safety.{{Cite web |last=Hracek |first=Filip |date=2020-06-10 |title=Announcing sound null safety |url=https://medium.com/dartlang/announcing-sound-null-safety-defd2216a6f3 |access-date=2023-05-12 |website=Dart |language=en}} This serves as a guarantee that variables cannot return a null value unless it has explicit permission. Null safety prevents the developer from introducing null-pointer exceptions, a common, but difficult to debug, error. With Dart 3.0, all code must follow sound null safety.

Data storage

Snapshot files, a core part of the Dart VM, store objects and other runtime data.

;Script snapshots

:Dart programs can be compiled into snapshot files containing all of the program code and dependencies preparsed and ready to execute, allowing fast startups.

;Full snapshots

:The Dart core libraries can be compiled into a snapshot file that allows fast loading of the libraries. Most standard distributions of the main Dart VM have a prebuilt snapshot for the core libraries that is loaded at runtime.

;Object snapshots

:Dart uses snapshots to serialize messages that it passes between isolates. As a very asynchronous language, Dart uses isolates for concurrency.{{Cite web |title=Concurrency in Dart |url=https://dart.dev/language/concurrency/ |access-date=2023-05-12 |website=dart.dev |language=en}} An object generates a snapshot, transfers it to another isolate, then the isolate deserializes it.

Editors

On November 18, 2011, Google released Dart Editor, an open-source program based on Eclipse components, for macOS, Windows, and Linux-based operating systems.{{cite web |url=http://dartr.com/google-releases-dart-editor/ |title=Google Releases Dart Editor for Windows, Mac OS X, and Linux |access-date=2011-11-29 |archive-url=https://web.archive.org/web/20131203024218/http://dartr.com/google-releases-dart-editor/ |archive-date=2013-12-03 |url-status=dead }} The editor supports syntax highlighting, code completion, JavaScript compiling, running web and server Dart applications, and debugging.

On August 13, 2012, Google announced the release of an Eclipse plugin for Dart development.{{Cite web|url=https://news.dartlang.org/2012/08/dart-plugin-for-eclipse-is-ready-for.html|title=Dart plugin for Eclipse is Ready for Preview|date=10 September 2019 }}

On April 18, 2015, Google retired the Dart Editor in favor of the JetBrains integrated development environment (IDE).{{Cite web|url=http://news.dartlang.org/2015/04/the-present-and-future-of-editors-and.html|title=The present and future of editors and IDEs for Dart|date=2015-04-30|access-date=2015-05-18|website=Dart News & Updates|last=Ladd|first=Seth}} Android Studio, IntelliJ IDEA, PyCharm, PhpStorm and WebStorm support a Dart plugin.{{cite web |title=JetBrains Plugin Repository : Dart |url=http://plugins.intellij.net/plugin/?idea&id=6351 |access-date=2013-07-21 |website=Plugins.intellij.net}} This plugin supports many features such as syntax highlighting, code completion, analysis, refactoring, debugging, and more. Other editors include plugins for Dart{{Cite web |title=Dart Tools |url=https://dart.dev/tools |access-date=2016-11-15 |website=dart.dev}} including Sublime Text,{{Cite web |title=Dart - Packages - Package Control |url=https://packagecontrol.io/packages/Dart |access-date=2023-05-13 |website=packagecontrol.io}} Atom,{{Cite web |title=dart - Dart plugin for Atom |url=https://dart-atom.github.io/dart/ |access-date=2023-05-13 |website=dart-atom.github.io}} Emacs,{{Citation |last=Trainor |first=Brady |title=bradyt/dart-mode |date=2023-04-15 |url=https://github.com/bradyt/dart-mode |access-date=2023-05-13}} Vim{{Citation |title=Dart Support for Vim |date=2023-05-09 |url=https://github.com/dart-lang/dart-vim-plugin |access-date=2023-05-13 |publisher=Dart}} and Visual Studio Code.{{Cite web |title=Dart - Visual Studio Marketplace |url=https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code |access-date=2023-05-13 |website=marketplace.visualstudio.com |language=en-us}}

=Chrome Dev Editor=

In 2013, the Chromium team began work on an open source, Chrome App-based development environment with a reusable library of GUI widgets, codenamed Spark.{{cite web |url=https://plus.google.com/+FrancoisBeaufort/posts/giSLiGvA4ye |first=François |last=Beaufort |title=The chromium team is currently actively working}} The project was later renamed as Chrome Dev Editor.{{cite web |url=https://github.com/dart-lang/spark |title =A Chrome app based development environment|website =GitHub|date =26 October 2021}} Built in Dart, it contained Spark which is powered by Polymer.{{Cite web |date=November 22, 2013 |title=Spark, A Chrome App from Google is an IDE for Your Chromebook |url=https://news.dartlang.org/2013/11/dart-used-to-build-new-development.html}}

In June 2015, Google transferred the CDE project to GitHub as a free software project and ceased active investment in CDE.{{cite web |url=https://plus.google.com/+SriSaroop/posts/6EwgknKpesS |first=Sri |last=Saroop |title=Chrome Dev Editor: Announcements}} The Chrome Dev Editor project was archived on April 24, 2021.{{Cite web|url=https://github.com/googlearchive/chromedeveditor|title=Chrome Dev Editor is a developer tool for building apps on the Chrome platform: Chrome Apps and Web Apps, in JavaScript or Dart. (NO LONGER IN ACTIVE DEVELOPMENT) - googlearchive/chromedeveditor|date=July 29, 2019|via=GitHub}}

=DartPad=

To provide an easier way to start using Dart, the Dart team created [https://dartpad.dev DartPad] at the start of 2015. This online editor allows developers to experiment with Dart application programming interfaces (APIs) and run Dart code. It provides syntax highlighting, code analysis, code completion, documentation, and HTML and CSS editing.{{Cite web|url=http://news.dartlang.org/2015/05/announcing-dartpad-friction-free-way-to.html|title=Announcing DartPad: A friction-free way to explore Dart code|last=Ladd|first=Seth|date=2015-05-06|website=Dart News & Updates|access-date=2015-05-18}}

Development tools

The Dart DevTools, written in Dart,{{Citation |title=Dart & Flutter DevTools |date=2023-05-12 |url=https://github.com/flutter/devtools |access-date=2023-05-12 |publisher=Flutter}} include debugging and performance tools.

Flutter

Google introduced Flutter for native app development. Built using Dart, C, C++ and Skia, Flutter is an open-source, multi-platform app UI framework. Prior to Flutter 2.0, developers could only target Android, iOS and the web. Flutter 2.0 released support for macOS, Linux, and Windows as a beta feature.{{Cite web |last=Sells |first=Chris |date=2021-03-03 |title=What's New in Flutter 2.0 |url=https://medium.com/flutter/whats-new-in-flutter-2-0-fe8e95ecc65 |access-date=2023-05-12 |website=Flutter |language=en}} Flutter 2.10 released with production support for Windows{{Cite web |last=Sneath |first=Tim |date=February 3, 2022 |title=Announcing Flutter for Windows |url=https://medium.com/flutter/announcing-flutter-for-windows-6979d0d01fed |website=}} and Flutter 3 released production support for all desktop platforms.{{Cite web |last=Chisholm |first=Kevin |date=2022-05-12 |title=What's new in Flutter 3 |url=https://medium.com/flutter/whats-new-in-flutter-3-8c74a5bc32d0 |access-date=2023-05-12 |website=Flutter |language=en}} It provides a framework, widgets, and tools. This framework gives developers a way to build and deploy mobile, desktop, and web apps.{{Cite web |title=FAQ |url=https://flutter.dev/docs/resources/faq |access-date=2021-08-29 |website=flutter.dev |language=en}} Flutter works with Firebase{{Cite web |title=Firebase |url=https://flutter.dev/docs/development/data-and-backend/firebase |access-date=2021-08-29 |website=flutter.dev |language=en}} and supports extending the framework through add-ons called packages. These can be found on their package repository, pub.dev.{{Cite web |title=Dart packages |url=https://pub.dev/ |access-date=2023-05-12 |website=Dart packages |language=en-us}} JetBrains also supports a Flutter plugin.{{Cite web |title=Flutter - IntelliJ IDEs Plugin {{!}} Marketplace |url=https://plugins.jetbrains.com/plugin/9212-flutter |access-date=2023-05-13 |website=JetBrains Marketplace}}

Example

A Hello, World! example:

void main() {

print('Hello, World!');

}

A simple for-loop:{{Cite web | title=Loops in Dart {{!}} Fluter World {{!}} Dart and Flutter Tutorials | url=https://www.flutterworld.tech/tutorials/dart-tutorials/dart-basics/loops-in-dart/#for-loop}}

void main() {

for (var i = 1; i <= 10; i++) {

print(i);

}

}

A function to calculate the nth Fibonacci number:

void main() {

var i = 20;

print('fibonacci($i) = ${fibonacci(i)}');

}

/// Computes the nth Fibonacci number.

int fibonacci(int n) {

return n < 2 ? n : (fibonacci(n - 1) + fibonacci(n - 2));

}

A simple class:

// Import the math library to get access to the sqrt function.

// Imported with `math` as name, so accesses need to use `math.` as prefix.

import 'dart:math' as math;

// Create a class for Point.

class Point {

// Final variables cannot be changed once they are assigned.

// Declare two instance variables.

final num x, y;

// A constructor, with syntactic sugar for setting instance variables.

// The constructor has two mandatory parameters.

Point(this.x, this.y);

// A named constructor with an initializer list.

Point.origin()

: x = 0,

y = 0;

// A method.

num distanceTo(Point other) {

var dx = x - other.x;

var dy = y - other.y;

return math.sqrt(dx * dx + dy * dy);

}

// Example of a "getter".

// Acts the same as a final variable, but is computed on each access.

num get magnitude => math.sqrt(x * x + y * y);

// Example of operator overloading

Point operator +(Point other) => Point(x + other.x, y + other.y);

// When instantiating a class such as Point in Dart 2+, new is

// an optional word

}

// All Dart programs start with main().

void main() {

// Instantiate point objects.

var p1 = Point(10, 10);

print(p1.magnitude);

var p2 = Point.origin();

var distance = p1.distanceTo(p2);

print(distance);

}

Influences from other languages

Dart belongs to the ALGOL language family.{{cite web|url=http://c2.com/cgi/wiki?AlgolFamily|title=Algol Family|work=c2.com}}{{Failed verification|date=September 2023}} Its members include C, Java, C#, JavaScript, and others.

The method cascade syntax was adopted from Smalltalk.{{Cite web |title=Method Cascades in Dart |date=10 September 2019 |url=https://news.dartlang.org/2012/02/method-cascades-in-dart-posted-by-gilad.html |access-date=2023-05-13 |language=en}} This syntax provides a shortcut for invoking several methods one after another on the same object.

Dart's mixins were influenced by Strongtalk{{Citation needed|reason=Just seeing a citation implies it is true, the paper on Smalltalk/Strongtalk predates Dart so does not say for sure. Maybe someone know it is based on Strongtalk mixins. Strongtalk wasn't first to introduce mixins. No expert on mixins – are there different variants and for sure Strongtalk the first to use this variant? Even then would someone have to say that it is based on that language?|date=March 2014}}{{cite journal

| last1=Bracha

| first1=Gilad

| last2=Griswold

| first2=David

| date=September 1996

| title=Extending the Smalltalk Language with Mixins

| url=http://ftp.linux62.org/~glibersat/publis/p331-bracha.pdf

| journal=OOPSLA Workshop

| publisher=OOPSLA

}}{{Cite web |last=Ladd |first=Seth |date=November 13, 2011 |title=Transcription of A Quick Tour of Dart by Gilad Bracha |url=http://blog.sethladd.com/2011/11/transcription-of-quick-tour-of-dart-by.html |access-date=2023-05-13 |language=en}} and Ruby.

Dart makes use of isolates as a concurrency and security unit when structuring applications.{{cite web|url=http://www.infoq.com/articles/google-dart/|title=The Essence of Google Dart: Building Applications, Snapshots, Isolates|work=InfoQ}} The Isolate concept builds upon the Actor model implemented in Erlang.{{Cite web |title=Fearless concurrency: how Clojure, Rust, Pony, Erlang and Dart let you achieve that. - Renato Athaydes |url=https://sites.google.com/a/athaydes.com/renato-athaydes/posts/fearlessconcurrencyhowclojurerustponyerlanganddartletyouachievethat#TOC-The-Actor-Model-Erlang-Dart- |access-date=2023-05-13 |website=sites.google.com |archive-date=2023-05-13 |archive-url=https://web.archive.org/web/20230513052456/https://sites.google.com/a/athaydes.com/renato-athaydes/posts/fearlessconcurrencyhowclojurerustponyerlanganddartletyouachievethat#TOC-The-Actor-Model-Erlang-Dart- |url-status=dead }}

In 2004, Gilad Bracha (who was a member of the Dart team) and David Ungar first proposed Mirror API for performing controlled and secure reflection in a paper.{{cite journal

| last1=Bracha

| first1=Gilad

| last2=Ungar

| first2=David

| year=2004

| title=Mirrors: design principles for meta-level facilities of object-oriented programming languages

| url=http://ftp.linux62.org/~glibersat/publis/p331-bracha.pdf

| journal=ACM SIGPLAN Notices

| publisher=ACM

| volume=39

| issue=10

| pages=331–344

| doi=10.1145/1035292.1029004

| access-date=15 February 2014

}} The concept was first implemented in Self.

See also

{{Portal|Computer programming|Free and open-source software}}

References

{{Reflist|30em}}

Bibliography

{{Refbegin}}

  • {{cite book

| last1=Walrath

| first1=Kathy

| last2=Ladd

| first2=Seth

| date=March 7, 2012

| title=What is Dart?

| publisher=O'Reilly Media

| edition=1st

| page=20

| isbn=978-14493-32327

| url=http://shop.oreilly.com/product/0636920025887.do

}}

  • {{cite book

| last1=Walrath

| first1=Kathy

| last2=Ladd

| first2=Seth

| date=November 7, 2012

| title=Dart: Up and Running

| publisher=O'Reilly Media

| edition=1st

| page=144

| isbn=978-1449330897

| url=http://shop.oreilly.com/product/0636920025719.do

}}

  • {{cite book

| last=Buckett

| first=Chris

| date=December 28, 2012

| title=Dart in Action

| publisher=Manning Publications

| edition=1st

| page=475

| isbn=978-1617290862

| url=

}}

{{Refend}}