
Learning Dart

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:
.
after a name you get a list of available properties and methods)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.
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:
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.
Change the font size
Change margin width
Change background colour