Chapter 1. Hello Dart
Listing 1.1. String interpolation in Dart
Listing 1.2. A simple class in Dart
Listing 1.3. Every class has an implicit interface
Listing 1.4. Factory constructors for default implementations
Listing 1.5. Libraries and source files
Listing 1.6. Functions as first-class objects
Chapter 2. “Hello World” with Dart tools
Listing 2.2. HTML file that can run your Dart app in both Dart and JavaScript
Listing 2.3. HelloWorld.dart.js: output of dart2js
Chapter 3. Building and testing your own Dart app
Listing 3.1. Adding a new Element to the document body
Listing 3.2. Building the PackList UI
Listing 3.3. PackList that reacts to user events
Listing 3.4. Basic class structure
Listing 3.5. Refactoring the addltem method to use your class
Listing 3.6. Adding a uiElement getter
Listing 3.7. Adding the isPacked property, getter, and setter
Listing 3.8. PackListTest.html: entry-point HTML file for your unit test
Listing 3.9. PackListTest.dart: client-side test suite boilerplate code
Chapter 4. Functional first-class functions and closures
Listing 4.1. Mixing concrete in Dart
Listing 4.2. Checking parameters passed by reference
Listing 4.3. Function that takes a function object as a parameter
Listing 4.4. Outer main() function uses the inner mix() function
Listing 4.5. Storing anonymous functions in a list
Listing 4.6. Recursive, typed, named function
Listing 4.7. Function type strongly types a function variable or parameter
Listing 4.8. Using typedef to declare a function signature
Listing 4.9. Creating a closure with a function as a return type
Chapter 5. Understanding libraries and privacy
Listing 5.1. loglib.dart functions and classes
Listing 5.2. packlist.dart importing the loglib.dart library
Listing 5.3. Generated JavaScript extract of the PackList app and loglib library
Listing 5.4. Adding logging method calls to the PackList application
Listing 5.5. packlist.dart using the Logger class imported from loglib
Listing 5.6. mixed_loglib.dart: library containing both public and private classes
Listing 5.7. loglib.dart with a private function
Listing 5.8. Complete functions.dart source file
Chapter 6. Constructing classes and interfaces
Listing 6.1. A simple User class
Listing 6.2. logon.dart: using an example AuthService
Listing 6.3. Using a mock authentication service
Listing 6.4. Defining an explicit interface
Listing 6.5. Implementing multiple interfaces
Listing 6.6. Using EnterpriseAuthService with multiple interfaces
Listing 6.7. logon_library.dart: getters, setters, and properties in interfaces
Listing 6.8. Using factory constructors for default implementations
Listing 6.9. Using a factory constructor to return an existing object from cache
Chapter 7. Extending classes and interfaces
Listing 7.2. EnterpriseUser with additional functionality
Listing 7.3. EnterpriseUser overriding functionality from parent User class
Listing 7.4. logon.dart: overriding properties inherited from the parent class
Listing 7.5. Making User an abstract class
Listing 7.6. Calling toString() outputs a textual representation of the object
Listing 7.7. Overriding the toString() functionality from Object
Chapter 8. Collections of richer classes
Listing 8.1. Permissions boilerplate code
Listing 8.2. Returning a list of AdminPermissions
Listing 8.3. Extracting the first two items from a collection using an iterator
Listing 8.4. Different ways to create a list
Listing 8.5. Creating and using a map of String and User
Listing 8.6. Using the dart:json library to convert between maps and strings
Listing 8.7. Using the Map putIfAbsent() method
Listing 8.8. User class that uses generic credentials
Listing 8.9. Using your generic User class in a type-safe manner
Listing 8.10. Ways to compare roles
Listing 8.11. Providing implementations of < and > with the operator keyword
Listing 8.12. Overloading the addition operator to add Roles to a User
Listing 8.13. Overloading the indexer operators
Listing 8.14. Letting a class implement Map so it can be converted to JSON
Chapter 9. Asynchronous programming with callbacks and futures
Listing 9.1. lottery_app.dart written in a synchronous, blocking style
Listing 9.2. lottery_app.dart: using callbacks
Listing 9.3. lottery.dart: adding a timer to getWinningNumber()
Listing 9.4. lottery_app.dart: introducing sequencing into an async callback
Listing 9.5. lottery_app.dart: using nested callbacks
Listing 9.6. lottery_app.dart using Future values and then() callbacks
Listing 9.7. lottery_app.dart: passing future values into a function
Listing 9.8. lottery_app.dart: chaining futures together to enforce ordering
Listing 9.9. lottery_app.dart: waiting for futures and chaining
Listing 9.10. lottery_app.dart: transforming a nonfuture value into a future value
Listing 9.11. lottery_test.dart: unit-testing getResultsString()
Listing 9.12. lottery_test.dart: testing async callback functions with expectAsync()
Listing 9.13. lottery_test.dart: testing multiple futures with wait() and expectAsync ()
Chapter 10. Building a Dart web app
Listing 10.1. DartExpense.html
Listing 10.2. DartExpense.dart main() function
Listing 10.3. Populating the content and actions <div>s with a view
Listing 10.4. ListView class, which builds the HTML table of expenses
Listing 10.5. getDynamicTable() to dynamically build an HTML table
Listing 10.6. Attaching an event handler to the Add button
Listing 10.7. Using the specific MouseEvent type to extract more event details
Chapter 11. Navigating offline data
Listing 11.1. Updated navigate() function that integrates with browser history
Listing 11.2. Updated main() function to listen for popState events
Listing 11.3. Utility function to extract a cookie value for a given cookie key
Listing 11.4. Changing the application’s first view if there’s a stateData cookie
Listing 11.5. Providing a toMap() method on the Expense and ExpenseType classes
Listing 11.6. Implementing the Map interface to support JSON.stringify()
Listing 11.7. fromMap() constructor: initializes an object from a map of properties
Listing 11.8. Adding/updating an expense in local storage
Listing 11.9. Reading the list of expenses out of local storage
Chapter 12. Communicating with other systems and languages
Listing 12.1. app.dart: sendToJavaScript() function that calls postMessage()
Listing 12.2. ui_chart.dart: ChartView class that calls the JavaScript chart library
Listing 12.3. DartExpense.html: JavaScript to receive postMessage() data
Listing 12.4. Calling Chart library code from receiveFromDart()
Listing 12.5. JavaScript sendToDart() utility function
Listing 12.6. ui_chart.dart: receiving data from JavaScript into Dart
Listing 12.7. ui_edit.dart: converting from USD to GBP
Listing 12.8. ui_list.dart: enabling the View Chart button only if the app is online
Listing 12.10. manifest.json: settings for creating an installable Chrome app
Chapter 13. Server interaction with files and HTTP
Listing 13.1. Accessing command-line options
Listing 13.2. Display the command-line options if none are provided
Listing 13.3. Implementing outputFile() with an InputStream
Listing 13.4. Serving simple HttpRequests from Dart
Listing 13.5. Serving static files
Listing 13.6. Updated main() function using all three handler classes
Listing 13.7. Implementing the FolderListHandler class
Listing 13.8. Sending data to the browser with FileContentHandler
Listing 13.9. The client-side part of the Dart File Browser application
Listing 13.10. Client HTML file hosting the client-side application
Chapter 14. Sending, syncing, and storing data
Listing 14.1. DartExpense.dart main() function creating a web socket connection
Listing 14.2. Adding connectToWebsocket() to the AppController class
Listing 14.3. Sending a client count when each browser connects
Listing 14.4. Adding onClosed() handler to the connection
Listing 14.5. Sending JSON data to the server with web sockets
Listing 14.6. Receiving and resending data from a web socket message
Listing 14.7. Receiving synchronization data in the browser
Listing 14.8. models.dart: Expense class updated to include a _rev JSON property
Listing 14.9. CouchDbHandler class’s _getStringFromInputStream() utility method
Listing 14.10. CouchDbHandler class’s _getData() utility method
Listing 14.11. CouchDbHandler: adding specific DartExpense functionality
Chapter 15. Concurrency with isolates
Listing 15.1. directoryAnalysis.dart
Listing 15.2. FileTypes isolate receiving data from the default isolate
Listing 15.3. Performing the file type and file size analyses in separate isolates
Listing 15.4. FileTypes and FileSizes isolates send results to the default isolate.
Listing 15.5. Closing a ReceivePort when all data is received
Listing 15.6. DirAnalysis.dart: reading the command-line arguments
Listing 15.7. DirAnalysis.dart: using spawnUri() to load a source file dynamically
Listing 15.8. Adding the receive handler to the isolate
Listing 15.9. batchDirAnalysis.dart: starting point for the batch application
Listing 15.10. Spawning worker isolates and passing initial data items
Listing 15.11. Implementing the default isolate receive() function
Appendix B. Defining classes and libraries
18.118.7.102