Book Image

Learning Dart

Book Image

Learning Dart

Overview of this book

Table of Contents (19 chapters)
Learning Dart
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, OS X, 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

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

  • Folding/unfolding code blocks

  • Tools for navigating 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 https://www.dartlang.org/tools/editor/ and play with one of the samples such as Sunflower or Pop, Pop, Win! (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 changes.

The Dart execution model

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

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 or Chrome (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 recent browsers

Code libraries in Dart are called packages and the core Dart SDK contains the basic types and functionalities for working with collection, math, html, uri, json, and so on. They can be recognized by the syntax dart:prefix, 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 you can find by navigating to Tools | Generate Dartdoc in Dart Editor), 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 Upgrade) and you can also publish your apps with it in the web repository http://pub.dartlang.org/.

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