logo资料库

dart-up-and-running.pdf

第1页 / 共136页
第2页 / 共136页
第3页 / 共136页
第4页 / 共136页
第5页 / 共136页
第6页 / 共136页
第7页 / 共136页
第8页 / 共136页
资料共136页,剩余部分请下载后查看
Copyright
Table of Contents
Foreword
Preface
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgments
Chapter 1. Quick Start
Why Google Created Dart
A Quick Look at the Dart Language
What’s Cool About Dart
Up and Running
Step 1: Download and Install the Software
Step 2: Launch the Editor
Step 3: Create and Run an App
Step 4: Open and Run a Sample
What Next?
Chapter 2. A Tour of the Dart Language
A Basic Dart Program
Important Concepts
Runtime Modes
Variables
Default Value
Optional Types
Final and Const
Built-in Types
Numbers
Strings
Booleans
Lists
Maps
Functions
Optional Parameters
Functions as First-Class Objects
Lexical Closures
Return Values
Operators
Arithmetic Operators
Equality and Relational Operators
Type Test Operators
Assignment Operators
Logical Operators
Bitwise and Shift Operators
Other Operators
Control Flow Statements
If and Else
For Loops
While and Do-While
Break and Continue
Switch and Case
Assert
Exceptions
Throw
Catch
Finally
Classes
Instance Variables
Constructors
Methods
Abstract Classes
Implicit Interfaces
Extending a Class
Class Variables and Methods
Generics
Why Use Generics?
Using Collection Literals
Using Constructors
Generic Collections and the Types they Contain
Libraries and Visibility
Using Libraries
Implementing Libraries
Isolates
Typedefs
Comments
Single-Line Comments
Multi-Line Comments
Documentation Comments
Summary
Chapter 3. A Tour of the Dart Libraries
dart:core - Numbers, Collections, Strings, and More
Numbers
Strings and Regular Expressions
Collections
Dates and Times
Utility Classes
Asynchronous Programming
Exceptions
dart:math - Math and Random
Trigonometry
Maximum and Mininum
Math Constants
Random Numbers
More Information
dart:html - Browser-Based Apps
Manipulating the DOM
Using HTTP Resources with HttpRequest
Sending and Receiving Real-Time Data with WebSockets
dart:isolate - Concurrency with Isolates
Isolate Concepts
Using Isolates
More Information
dart:io - I/O for Command-Line Apps
Files and Directories
HTTP Clients and Servers
dart:json - Encoding and Decoding Objects
Decoding JSON
Encoding JSON
dart:uri - Manipulating URIs
Encoding and Decoding Fully Qualified URIs
Encoding and Decoding URI Components
Parsing URIs
Building URIs
dart:utf - Strings and Unicode
Decoding UTF-8 Characters
Encoding Strings to UTF-8 Bytes
Other Functionality
dart:crypto - Hash Codes and More
Generating Cryptographic Hashes
Generating Message Authentication Codes
Generating Base64 Strings
Summary
Chapter 4. Tools
pub: The Dart Package Manager
Creating a Pubspec
Installing Packages
Importing Libraries from Packages
More Information
Dart Editor
Viewing Samples
Managing the Files View
Creating Apps
Editing Apps
Running Apps
Debugging Apps
Compiling to JavaScript
Other Features
Dartium: Chromium with the Dart VM
Downloading and Installing the Browser
Launching the Browser
Filing Bugs
Linking to Dart Source
Detecting Dart Support
Launching from the Command Line
dart2js: The Dart-to-JavaScript Compiler
Basic Usage
Options
dart: The Standalone VM
Basic Usage
Enabling Checked Mode
Additional Options
Summary
Chapter 5. Walkthrough: Dart Chat
How to Run Dart Chat
How Dart Chat Works
The Client’s HTML Code
The Client’s Dart Code
Finding DOM Elements
Wrapping DOM Elements
Updating DOM Elements
Encoding and Decoding Messages
Communicating with WebSockets
The Server’s Code
Serving Static Files
Managing WebSocket Connections
Logging Messages to a File
What Next?
About the Authors
Dart: Up and Running Kathy Walrath and Seth Ladd
Dart: Up and Running by Kathy Walrath and Seth Ladd Copyright © 2013 Kathy Walrath, Seth Ladd. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/ institutional sales department: 800-998-9938 or corporate@oreilly.com. Editor: Meghan Blanchette Production Editor: Christopher Hearse Proofreader: Christopher Hearse Cover Designer: Randy Comer Interior Designer: David Futato Illustrator: Rebecca Demarest Revision History for the First Edition: 2012-10-24 First release See http://oreilly.com/catalog/errata.csp?isbn=9781449330897 for release details. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Dart: Up and Running, the image of a greater roadrunner, and related trade dress are trademarks of O’Reilly Media, Inc. This text of this work is available at this book’s GitHub project under the Creative Commons Attribution- Noncommercial-No Derivative Works 3.0 United States License. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trade‐ mark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN: 978-1-449-33089-7 [LSI]
Table of Contents Foreword. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi 1. Quick Start. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Why Google Created Dart 1 A Quick Look at the Dart Language 3 What’s Cool About Dart 3 Up and Running 5 Step 1: Download and Install the Software 5 Step 2: Launch the Editor 5 Step 3: Create and Run an App 6 Step 4: Open and Run a Sample 8 What Next? 9 2. A Tour of the Dart Language. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 A Basic Dart Program 11 Important Concepts 12 Runtime Modes 13 Variables 13 Default Value 14 Optional Types 14 Final and Const 14 Built-in Types 15 Numbers 15 Strings 16 Booleans 17 Lists 18 Maps 19 Functions 20 Optional Parameters 20 iii
Functions as First-Class Objects 22 Lexical Closures 22 Return Values 23 Operators 23 Arithmetic Operators 24 Equality and Relational Operators 25 Type Test Operators 26 Assignment Operators 26 Logical Operators 27 Bitwise and Shift Operators 27 Other Operators 28 Control Flow Statements 28 If and Else 28 For Loops 29 While and Do-While 29 Break and Continue 30 Switch and Case 30 Assert 32 Exceptions 32 Throw 32 Catch 33 Finally 33 Classes 34 Instance Variables 35 Constructors 35 Methods 39 Abstract Classes 41 Implicit Interfaces 42 Extending a Class 43 Class Variables and Methods 43 Generics 44 Why Use Generics? 44 Using Collection Literals 45 Using Constructors 46 Generic Collections and the Types they Contain 46 Libraries and Visibility 46 Using Libraries 46 Implementing Libraries 47 Isolates 49 Typedefs 49 Comments 51 Single-Line Comments 51 iv | Table of Contents
Multi-Line Comments 51 Documentation Comments 51 Summary 52 3. A Tour of the Dart Libraries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 dart:core - Numbers, Collections, Strings, and More 53 Numbers 53 Strings and Regular Expressions 54 Collections 57 Dates and Times 62 Utility Classes 63 Asynchronous Programming 64 Exceptions 66 dart:math - Math and Random 66 Trigonometry 66 Maximum and Mininum 67 Math Constants 67 Random Numbers 67 More Information 67 dart:html - Browser-Based Apps 68 Manipulating the DOM 68 Using HTTP Resources with HttpRequest 72 Sending and Receiving Real-Time Data with WebSockets 74 dart:isolate - Concurrency with Isolates 76 Isolate Concepts 76 Using Isolates 77 More Information 80 dart:io - I/O for Command-Line Apps 80 Files and Directories 80 HTTP Clients and Servers 83 dart:json - Encoding and Decoding Objects 84 Decoding JSON 85 Encoding JSON 85 dart:uri - Manipulating URIs 86 Encoding and Decoding Fully Qualified URIs 86 Encoding and Decoding URI Components 86 Parsing URIs 87 Building URIs 87 dart:utf - Strings and Unicode 87 Decoding UTF-8 Characters 87 Encoding Strings to UTF-8 Bytes 88 Other Functionality 88 Table of Contents | v
dart:crypto - Hash Codes and More 88 Generating Cryptographic Hashes 89 Generating Message Authentication Codes 89 Generating Base64 Strings 89 Summary 90 4. Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 pub: The Dart Package Manager 91 Creating a Pubspec 92 Installing Packages 92 Importing Libraries from Packages 93 More Information 93 Dart Editor 93 Viewing Samples 93 Managing the Files View 93 Creating Apps 94 Editing Apps 95 Running Apps 99 Debugging Apps 101 Compiling to JavaScript 102 Other Features 102 Dartium: Chromium with the Dart VM 103 Downloading and Installing the Browser 103 Launching the Browser 104 Filing Bugs 104 Linking to Dart Source 104 Detecting Dart Support 105 Launching from the Command Line 105 dart2js: The Dart-to-JavaScript Compiler 105 Basic Usage 106 Options 106 dart: The Standalone VM 106 Basic Usage 106 Enabling Checked Mode 106 Additional Options 107 Summary 107 5. Walkthrough: Dart Chat. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 How to Run Dart Chat 109 How Dart Chat Works 110 The Client’s HTML Code 111 The Client’s Dart Code 112 vi | Table of Contents
分享到:
收藏