Book Image

Learning Dart, Second Edition - Second Edition

By : Ivo Balbaert
Book Image

Learning Dart, Second Edition - Second Edition

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Learning Dart Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Getting a view on the Dart tool chain


Dart comes with batteries included, which means that a complete stack of tools is provided by Google to write Dart apps, compile, test, document, and publish them. Moreover, these tools are platform-independent (being made for 32- and 64-bit Linux, OSX, and Windows) and they are integrated in the Dart Editor IDE. The Dart Editor contains everything a seasoned developer needs to work with confidence on his app:

  • Syntax coloring for keywords

  • Auto completion for class members (by typing . after a class name you get a list of available properties and methods of the current class)

  • Folding/unfolding code blocks

  • Tools to navigate the code (a handy overview of the code with the outline, find callers of a method, and so on)

  • Full debugging capabilities of both browser and server applications

  • Choose your preferred editor style by navigating to Tools | Preferences | Visual Theme

  • Quick fixes for common errors

  • Refactoring capabilities

  • Direct access to the online API documentation by navigating to Help | API Reference

The code you make is analyzed while you type, indicating warning (yellow triangles) or errors (red underscores or stop signs). To get more acquainted and experiment with these possibilities, go and read the documentation at http://www.dartlang.org/docs/editor/ and play with one of the samples such as Sunflower or Solar (you can find the samples by navigating to Tools | Welcome Page). From now on, use the editor in conjunction with the code examples of the book so that you can try them out and test the changes.

The Dart execution model

How a Dart app executes is sketched in the following diagram:

The Dart execution model

The Dart code produced in the Dart Editor (or in a plugin for Eclipse or IntelliJ) can:

  • Execute in the Dart VM, hosted in Dartium (Dartium is an experimental version of Chrome to test out Dart) or directly in the operating system (the browser VM knows about HTML, the server VM does not, but can use, for example, IO and sockets, so they are not completely equivalent)

  • Be compiled to JS with the dart2js compiler so that it can run in all the recent browsers

Code libraries in Dart are called packages and the Dart SDK core contains the basic types and functionalities to work with collection, math, html, uri, json, and so on. They can be recognized by the dart:prefix syntax, for example, dart:html. If you want to use a functionality from a library in a code file, you must import it by using the following as the first statement(s) in your code (dart:core is imported by default):

import 'dart:html';

The Dart code can be tested with the unit test package and, for documentation, you can use the dartdoc tool, which generates a local website structured like the official API documentation on the Web. The pub tool is the Dart package manager: if your app needs other packages besides the SDK, pub can install them for you (from the Tools menu item in Dart Editor, select Pub Get or Pub Update). You can also publish your apps with it in the http://pub.dartlang.org/ web repository.

We will see all of these tools in action in Chapter 2, Getting to Work with Dart.