Getting started with dart

Download dart eBook

Remarks

Dart logo

Dart is an open-source, class-based, optionally-typed programming language for building web applications--on both the client and server--created by Google. Dart’s design goals are:

  • Create a structured yet flexible language for web programming.
  • Make Dart feel familiar and natural to programmers and thus easy to learn.
  • Ensure that Dart delivers high performance on all modern web browsers and environments ranging from small handheld devices to server-side execution.

Dart targets a wide range of development scenarios, from a one-person project without much structure to a large-scale project needing formal types in the code to state programmer intent.

To support this wide range of projects, Dart provides the following features and tools:

  • Optional types: this means you can start coding without types and add them later as needed.
  • Isolates: concurrent programming on server and client
  • Easy DOM access: using CSS selectors (the same way that jQuery does it)
  • Dart IDE Tools: Dart plugins exist for many commonly used IDEs, Ex: WebStorm.
  • Dartium: a build of the Chromium Web Browser with a built-in Dart Virtual Machine

Links

Documentation

FAQ

Versions

VersionRelease Date
1.22.12017-02-22
1.22.02017-02-14
1.21.12016-01-13
1.21.02016-12-07
1.20.12016-10-13
1.20.02016-10-11
1.19.12016-09-07
1.19.02016-08-26
1.18.12016-08-02
1.18.02016-07-27
1.17.12016-06-10
1.17.02016-06-06
1.16.12016-05-23
1.16.02016-04-26
1.15.02016-03-09
1.14.22016-02-09
1.14.12016-02-03
1.14.02016-01-28
1.13.22016-01-05
1.13.12015-12-17
1.13.02015-11-18
1.12.22015-10-21
1.12.12015-09-08
1.12.02015-08-31
1.11.32015-08-03
1.11.12015-07-02
1.11.02015-06-24
1.10.12015-05-11
1.10.02015-04-24
1.9.32015-04-13
1.9.12015-03-25
1.8.52015-01-13
1.8.32014-12-01
1.8.02014-11-27
1.7.22014-10-14
1.6.02014-08-27
1.5.82014-07-29
1.5.32014-07-03
1.5.22014-07-02
1.5.12014-06-24
1.4.32014-06-16
1.4.22014-05-27
1.4.02014-05-20
1.3.62014-04-30
1.3.32014-04-16
1.3.02014-04-08
1.2.02014-02-25
1.1.32014-02-06
1.1.12014-01-15
1.0.0.10_r307982013-12-02
1.0.0.3_r301882013-11-12
0.8.10.10_r301072013-11-08
0.8.10.6_r300362013-11-07
0.8.10.3_r298032013-11-04

Getters and Setters

void main() {
  var cat = new Cat();
  
  print("Is cat hungry? ${cat.isHungry}");  // Is cat hungry? true
  print("Is cat cuddly? ${cat.isCuddly}");  // Is cat cuddly? false
  print("Feed cat.");
  cat.isHungry = false;                     
  print("Is cat hungry? ${cat.isHungry}");  // Is cat hungry? false
  print("Is cat cuddly? ${cat.isCuddly}");  // Is cat cuddly? true
}

class Cat {
  bool _isHungry = true;
  
  bool get isCuddly => !_isHungry;
  
  bool get isHungry => _isHungry;
  bool set isHungry(bool hungry) => this._isHungry = hungry;
}
 

Dart class getters and setters allow APIs to encapsulate object state changes.

See dartpad example here: https://dartpad.dartlang.org/c25af60ca18a192b84af6990f3313233

Hello, World!

Create a new file named hello_world.dart with the following content:

void main() {
  print('Hello, World!');
}
 

In the terminal, navigate to the directory containing the file hello_world.dart and type the following:

dart hello_world.dart
 

Hit enter to display Hello, World! in the terminal window.

Http Request

Html

<img id="cats"></img>
 

Dart

import 'dart:html';

/// Stores the image in [blob] in the [ImageElement] of the given [selector].
void setImage(selector, blob) {
  FileReader reader = new FileReader();
  reader.onLoad.listen((fe) { 
    ImageElement image = document.querySelector(selector);
    image.src = reader.result;
  });
  reader.readAsDataUrl(blob);  
}

main() async {
  var url = "https://upload.wikimedia.org/wikipedia/commons/2/28/Tortoiseshell_she-cat.JPG";

  // Initiates a request and asynchronously waits for the result.
  var request = await HttpRequest.request(url, responseType: 'blob');
  var blob = request.response;
  setImage("#cats", blob);
}
 

Example

see Example on https://dartpad.dartlang.org/a0e092983f63a40b0b716989cac6969a

Installation or Setup

The Dart SDK includes everything you need to write and run Dart code: VM, libraries, analyzer, package manager, doc generator, formatter, debugger, and more. If you are doing web development, you will also need Dartium.

Automated installation and updates

Manual install

You can also manually install any version of the SDK.

Stats

157 Contributors: 11
Monday, April 3, 2017
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook