You are previewing Dart Cookbook.
O'Reilly logo
Dart Cookbook

Book Description

Over 110 incredibly effective, useful, and hands-on recipes to design Dart web client and server applications

In Detail

Dart is a new open source programming language for the Web, developed at Google, with a steadily growing community. It is a single language for both client and server, and is apt for the complete range of devices on the Web, including phones, tablets, laptops, and servers. Stop solving new challenges with the same old tools—let Dart show you a new, simpler, and more unified way, which makes use of the same language for both client and server.

This book is a pragmatic guide that will increase your expertise in writing all kinds of applications, including web apps, scripts, and server-side apps. It provides rich insights on how to extend your Dart programming skills.

What You Will Learn

  • Set up your Dart environment to achieve the highest productivity
  • Structure, document, test, and deploy your apps
  • Use mixins, reflections, annotations, and other metadata programming techniques to create powerful apps
  • Use the power of modern browsers to process and store data
  • Communicate with JavaScript and use JavaScript libraries
  • Work with files, streams, and web servers by writing asynchronous code
  • Demonstrate the power of Polymer web components for binding data and structuring your web pages
  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. Dart Cookbook
      1. Table of Contents
      2. Dart Cookbook
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Working with Dart Tools
        1. Introduction
        2. Configuring the Dart environment
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Setting up the checked and production modes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Rapid Dart Editor troubleshooting
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        5. Hosting your own private pub mirror
          1. How to do it...
          2. How it works...
        6. Using Sublime Text 2 as an IDE
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Compiling your app to JavaScript
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Producing more readable JavaScript code
            2. Producing a single Dart file
          4. See also
        8. Debugging your app in JavaScript for Chrome
          1. How to do it…
          2. How it works...
          3. There's more...
            1. Debugging your app in JavaScript for Firefox
        9. Using the command-line tools
          1. How to do it...
          2. See also
        10. Solving problems when pub get fails
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        11. Shrinking the size of your app
          1. How to do it...
          2. How it works...
          3. There's more...
            1. More Information Section 1
          4. See also
        12. Making a system call
          1. How to do it...
          2. How it works...
        13. Using snapshotting
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        14. Getting information from the operating system
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      9. 2. Structuring, Testing, and Deploying an Application
        1. Introduction
        2. Exiting from an app
          1. How to do it...
            1. How it works...
        3. Parsing command-line arguments
          1. How to do it...
          2. How it works...
          3. See also
        4. Structuring an application
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Using a library from within your app
          1. How to do it...
          2. How it works...
          3. There's more...
        6. Microtesting your code with assert
          1. How to do it...
          2. How it works...
          3. There's more...
        7. Unit testing a Polymer web app
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        8. Adding logging to your app
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        9. Documenting your app
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        10. Profiling and benchmarking your app
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        11. Publishing and deploying your app
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        12. Using different settings in the checked and production modes
          1. How to do it...
          2. How it works...
      10. 3. Working with Data Types
        1. Introduction
        2. Concatenating strings
          1. How to do it...
          2. How it works...
          3. There's more...
        3. Using regular expressions
          1. How to do it...
          2. How it works...
          3. There's more...
        4. Strings and Unicode
          1. How to do it...
          2. How it works...
          3. There's more...
        5. Using complex numbers
          1. How to do it...
          2. How it works...
          3. There's more...
        6. Creating an enum
          1. How to do it...
          2. How it works...
          3. There's more...
        7. Flattening a list
          1. How to do it...
          2. How it works...
          3. There's more...
        8. Generating a random number within a range
          1. How to do it...
          2. How it works...
        9. Getting a random element from a list
          1. How to do it...
          2. How it works...
          3. See also
        10. Working with dates and times
          1. How to do it...
          2. How it works...
          3. There's more...
        11. Improving performance in numerical computations
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Working with JavaScript
            2. Parsing numbers
          4. See also
        12. Using SIMD for enhanced performance
          1. How to do it…
          2. How it works...
          3. See also
      11. 4. Object Orientation
        1. Introduction
        2. Testing and converting types
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        3. Comparing two objects
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        4. Using a factory constructor
          1. How to do it...
          2. How it works...
          3. There's more...
        5. Building a singleton
          1. How to do it...
          2. How it works...
        6. Using reflection
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Using mixins
          1. How to do it...
          2. How it works...
          3. There's more...
        8. Using annotations
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        9. Using the call method
          1. How to do it...
          2. How it works...
          3. There's more...
        10. Using noSuchMethod
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        11. Making toJSON and fromJSON methods in your class
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        12. Creating common classes for client and server apps
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
      12. 5. Handling Web Applications
        1. Introduction
        2. Responsive design
          1. How to do it...
          2. How it works...
          3. See also
        3. Sanitizing HTML
          1. How to do it...
          2. How it works...
        4. Using a browser's local storage
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        5. Using application cache to work offline
          1. How to do it...
          2. How it works...
          3. There's more...
        6. Preventing an onSubmit event from reloading the page
          1. How to do it...
          2. How it works...
        7. Dynamically inserting rows in an HTML table
          1. How to do it...
          2. How it works...
          3. See also...
        8. Using CORS headers
          1. How to do it...
          2. How it works...
          3. There's more...
        9. Using keyboard events
          1. How to do it...
          2. How it works...
          3. There's more...
        10. Enabling drag-and-drop
          1. How to do it...
          2. How it works...
          3. See also
        11. Enabling touch events
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        12. Creating a Chrome app
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        13. Structuring a game project
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        14. Using WebGL in your app
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        15. Authorizing OAuth2 to Google services
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        16. Talking with JavaScript
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        17. Using JavaScript libraries
          1. How to do it...
          2. How it works...
          3. See also
      13. 6. Working with Files and Streams
        1. Introduction
        2. Reading and processing a file line by line
          1. How to do it...
          2. How it works...
          3. See also
        3. Writing to a file
          1. How to do it...
          2. How it works...
          3. There's more...
        4. Searching in a file
          1. How to do it...
          2. How it works...
          3. See also
        5. Concatenating files
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        6. Downloading a file
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Using pipe
            2. Using the http package
          5. See also
        7. Working with blobs
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Transforming streams
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
      14. 7. Working with Web Servers
        1. Introduction
        2. Creating a web server
          1. How to do it...
          2. How it works...
          3. There is more...
        3. Posting JSON-formatted data
          1. How to do it...
          2. How it works...
          3. See also
        4. Receiving data on the web server
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Writing data to a file on the server
          4. See also
        5. Serving files with http_server
          1. How to do it...
          2. How it works...
          3. There's more...
        6. Using sockets
          1. How to do it...
          2. How it works...
          3. There's more...
        7. Using WebSockets
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Using secure sockets and servers
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        9. Using a JSON web service
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      15. 8. Working with Futures, Tasks, and Isolates
        1. Introduction
        2. Writing a game loop
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        3. Error handling with Futures
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Scheduling tasks using Futures
          1. How to do it...
          2. How it works...
          3. See also
        5. Running a recurring function
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        6. Using isolates in the Dart VM
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        7. Using isolates in web apps
          1. How to do it...
          2. How it works...
          3. See also
        8. Using multiple cores with isolates
          1. How to do it...
          2. How it works...
        9. Using the Worker Task framework
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
      16. 9. Working with Databases
        1. Introduction
        2. Storing data locally with IndexedDB
          1. How to do it...
          2. How it works...
          3. See also
        3. Using Lawndart to write offline web apps
          1. How to do it...
          2. How it works...
          3. See also
        4. Storing data in MySQL
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        5. Storing data in PostgreSQL
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Storing data in Oracle
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        7. Storing data in MongoDB
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        8. Storing data in RethinkDB
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      17. 10. Polymer Dart Recipes
        1. Introduction
        2. Data binding with polymer.dart
          1. How to do it...
          2. How it works...
          3. There's more…
        3. Binding and repeating over a list
          1. How to do it...
          2. How it works...
          3. There's more...
        4. Binding to a map
          1. How to do it...
          2. How it works...
          3. See also
        5. Using custom attributes and template conditionals
          1. How to do it...
          2. How it works...
          3. See also
        6. Binding to an input text field or a text area
          1. How to do it...
          2. How it works...
        7. Binding to a checkbox
          1. How to do it...
          2. How it works...
          3. See also
        8. Binding to radio buttons
          1. How to do it...
          2. How it works...
        9. Binding to a selected field
          1. How to do it...
          2. How it works...
        10. Event handling
          1. How to do it...
          2. How it works...
        11. Polymer elements with JavaScript interop
          1. How to do it...
          2. How it works...
          3. See also
        12. Extending DOM elements
          1. How to do it...
          2. How it works...
        13. Working with custom elements
          1. How to do it...
          2. How it works...
          3. There's more...
        14. Automatic node finding
          1. How to do it...
          2. How it works...
        15. Internationalizing a Polymer app
          1. How to do it...
          2. How it works...
          3. There's more...
      18. 11. Working with Angular Dart
        1. Introduction
        2. Setting up an Angular app
          1. How to do it...
          2. How it works...
          3. There's more...
        3. Using a controller
          1. How to do it...
          2. How it works...
          3. There's more...
        4. Using a component
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        5. Using formatters as filters
          1. How to do it...
          2. How it works...
          3. See also
        6. Creating a view
          1. How to do it...
          2. How it works...
        7. Using a service
          1. How to do it...
          2. How it works...
          3. See also
        8. Deploying your app
          1. How to do it...
          2. How it works...
          3. See also
      19. Index