Dart: Up and Running

Book description

Get moving with Dart, the development platform that helps you build high-performance HTML5 apps for the modern Web. With this guide, you’ll take a hands-on tour of the Dart language, libraries, and tools—including its editor and virtual machine—for developing structured, fast, and maintainable web apps that run on both the client and the server.

Written by developer advocates at Google, this updated edition covers Dart 1.0. Google designed Dart to boost performance and help developers work more efficiently. This book shows you how to build everything from simple scripts to complex apps that work well in today’s browsers.

  • Build web apps with the object-oriented Dart language, and compile your code to JavaScript
  • Delve into language features, from optional types and method cascades to named constructors
  • Create, launch, and debug web and command-line apps with Dart Editor
  • Explore Dart APIs, including dart:core, dart:html, dart:io, dart:convert, and dart:mirrors
  • Use tools such as Dartium, the Chromium-based browser that can run Dart apps natively
  • Walk through Dartiverse Search, a client-server app that combines useful and fun language and API features

Table of contents

  1. Foreword
  2. Preface
    1. Conventions Used in This Book
    2. Using Code Examples
    3. Safari® Books Online
    4. How to Contact Us
    5. Content Updates
      1. Changes in the Third Printing: February 19, 2014
      2. Changes in the Second Printing: March 29, 2013
    6. Acknowledgments
  3. 1. Quick Start
    1. Why Google Created Dart
    2. A Quick Look at the Dart Language
    3. What’s Cool About Dart
    4. Up and Running
      1. Step 1: Download and Install the Software
      2. Step 2: Launch the Editor
      3. Step 3: Open and Run a Demo
      4. Step 4: Create and Run an App
      5. What Next?
        1. Follow a code lab
        2. Read tutorials
        3. Become a power user
        4. Send feedback
  4. 2. A Tour of the Dart Language
    1. A Basic Dart Program
    2. Important Concepts
      1. Keywords
      2. Runtime Modes
    3. Variables
      1. Default Value
      2. Optional Types
      3. Final and Const
    4. Built-in Types
      1. Numbers
      2. Strings
      3. Booleans
      4. Lists
      5. Maps
      6. Symbols
    5. Functions
      1. Optional Parameters
        1. Optional named parameters
        2. Optional positional parameters
      2. The main() Function
      3. Functions as First-Class Objects
      4. Lexical Scope
      5. Lexical Closures
      6. Testing Functions for Equality
      7. Return Values
    6. Operators
      1. Arithmetic Operators
      2. Equality and Relational Operators
      3. Type Test Operators
      4. Assignment Operators
      5. Logical Operators
      6. Bitwise and Shift Operators
      7. Other Operators
    7. Control Flow Statements
      1. If and Else
      2. For Loops
      3. While and Do-While
      4. Break and Continue
      5. Switch and Case
      6. Assert
    8. Exceptions
      1. Throw
      2. Catch
      3. Finally
    9. Classes
      1. Instance Variables
      2. Constructors
        1. Default constructors
        2. Constructors aren’t inherited
        3. Named constructors
        4. Invoking a non-default superclass constructor
        5. Initializer list
        6. Redirecting constructors
        7. Constant constructors
        8. Factory constructors
      3. Methods
        1. Instance methods
        2. Getters and setters
        3. Abstract methods
        4. Overridable operators
      4. Abstract Classes
      5. Implicit Interfaces
      6. Extending a Class
      7. Adding Features to a Class: Mixins
      8. Class Variables and Methods
        1. Static variables
        2. Static methods
    10. Generics
      1. Why Use Generics?
      2. Using Collection Literals
      3. Using Parameterized Types with Constructors
      4. Generic Collections and the Types They Contain
    11. Libraries and Visibility
      1. Using Libraries
        1. Specifying a library prefix
        2. Importing only part of a library
      2. Implementing Libraries
        1. Declaring a library
        2. Associating a file with a library
        3. Re-exporting libraries
    12. Isolates
    13. Typedefs
    14. Metadata
    15. Comments
      1. Single-Line Comments
      2. Multi-Line Comments
      3. Documentation Comments
    16. Summary
  5. 3. A Tour of the Dart Libraries
    1. dart:core—Numbers, Collections, Strings, and More
      1. Numbers
      2. Strings and Regular Expressions
        1. Searching inside a string
        2. Extracting data from a string
        3. Converting to uppercase or lowercase
        4. Trimming and empty strings
        5. Replacing part of a string
        6. Building a string
        7. Regular expressions
        8. More information
      3. Collections
        1. Lists
        2. Sets
        3. Maps
        4. Common collection methods
      4. URIs
        1. Encoding and decoding fully qualified URIs
        2. Encoding and decoding URI components
        3. Parsing URIs
        4. Building URIs
      5. Dates and Times
      6. Utility Classes
        1. Comparing objects
        2. Implementing map keys
        3. Iteration
      7. Exceptions
    2. dart:async—Asynchronous Programming
      1. Future
        1. Basic usage
        2. Chaining multiple asynchronous methods
        3. Waiting for multiple Futures
      2. Stream
        1. Listening for stream data
        2. Transforming stream data
      3. More Information
    3. dart:math—Math and Random
      1. Trigonometry
      2. Maximum and Minimum
      3. Math Constants
      4. Random Numbers
      5. More Information
    4. dart:html—Browser-Based Apps
      1. Manipulating the DOM
        1. Finding elements
        2. Manipulating elements
        3. Creating elements
        4. Adding, replacing, and removing nodes
        5. Manipulating CSS styles
        6. Handling events
      2. Using HTTP Resources with HttpRequest
        1. Getting data from the server
        2. Sending data to the server
      3. Sending and Receiving Real-Time Data with WebSockets
        1. Sending data
        2. Receiving data
        3. Handling WebSocket events
      4. More Information
    5. dart:io—I/O for Command-Line Apps
      1. Files and Directories
        1. Reading a file as text
        2. Reading a file as binary
        3. Handling errors
        4. Streaming file contents
        5. Writing file contents
        6. Listing files in a directory
        7. Other common functionality
      2. HTTP Clients and Servers
        1. HTTP server
        2. HTTP client
      3. More Information
    6. dart:convert—Decoding and Encoding JSON, UTF-8, and More
      1. Decoding and Encoding JSON
      2. Decoding and Encoding UTF-8 Characters
      3. Other Functionality
    7. dart:mirrors—Reflection
      1. Symbols
      2. Introspection
        1. Class Mirrors
        2. InstanceMirrors
      3. Invocation
        1. Invoke methods
        2. Invoke getters and setters
      4. More Information
    8. Summary
  6. 4. Tools
    1. pub: The Dart Package Manager
      1. Creating a Pubspec
      2. Installing Packages
      3. Importing Libraries from Packages
      4. More Information
    2. Dart Editor
      1. Viewing Samples
      2. Managing the Files View
        1. Adding apps
        2. Removing apps
      3. Creating Apps
      4. Editing Apps
        1. Using autocomplete
        2. Browsing APIs
          1. Finding out more about an API
          2. Outlining a file’s contents
        3. Refactoring
        4. Searching
      5. Running Apps
        1. Specifying launch configurations
        2. Running in production mode
        3. Specifying a browser for JavaScript launches
      6. Debugging Apps
      7. Compiling to JavaScript
      8. Other Features
        1. Customizing Dart Editor
        2. Keyboard alternatives
    3. Dartium: Chromium with the Dart VM
      1. Downloading and Installing the Browser
      2. Launching the Browser
      3. Filing Bugs
      4. Linking to Dart Source
      5. Detecting Dart Support
      6. Launching from the Command Line
    4. dart2js: The Dart-to-JavaScript Compiler
      1. Basic Usage
      2. Options
      3. Helping dart2js Generate Better Code
      4. Debugging
        1. Chrome
        2. Firefox
        3. Safari
    5. dart: The Standalone VM
      1. Basic Usage
      2. Options
      3. Enabling Checked Mode
    6. dartanalyzer: The Static Analyzer
      1. Basic Usage
      2. Options
    7. Summary
  7. 5. Walkthrough: Dartiverse Search
    1. How to Run Dartiverse Search
    2. How Dartiverse Search Works
    3. The Client’s HTML Code
    4. The Client’s Dart Code
      1. Finding DOM Elements
      2. Handling Events
      3. Getting and Setting Properties
      4. Adding DOM Elements
      5. Encoding and Decoding Messages
      6. Communicating with WebSockets
    5. The Server’s Code
      1. Serving Static Files
      2. Managing WebSocket Connections
      3. Using Web APIs
      4. Implementing a Library
      5. Logging Messages
    6. What Next?
  8. Copyright

Product information

  • Title: Dart: Up and Running
  • Author(s): Kathy Walrath, Seth Ladd
  • Release date: October 2012
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449330859