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

Book Description

Dart is the programming language developed by Google that offers a new level of simple versatility. Learn all the essentials of Dart web development in this brilliant tutorial that takes you from beginner to pro.

In Detail

Dart is a new open source programming language for the Web. Developed by Google, Dart is gaining popularity and has a steadily growing community. It is a single language for both client and server that can be used with a wide range of devices, including phones, tablets, laptops, and servers. It encompasses the lessons that have been learned over the last two decades of web programming. Stop solving new challenges with the same old tools - let Dart show you a whole new way.

"Learning Dart" provides you with a thorough overview of this new open source programming language. It will guide you step-by-step through building games and business applications for the Web, taking advantage of the power behind a modern language combined with HTML5.

"Learning Dart" starts by exploring the Dart ecosystem. This is followed by two chapters that will show you everything you need to know about Dart's syntax and development principles. Throughout the rest of the book, you will apply this knowledge to advanced topics with the help of an example-based approach.

You will explore how to build web games using HTML5, how to integrate audio and video into your applications, and how to process and show data in HTML5 forms with Dart. The book also shows you how web components fit together with HTML5 and how to apply them in business web applications. You also learn how to store data on the client, how to communicate data between client and server with JSON, and how to store JSON data with MongoDB.

"Learning Dart" provides you with everything you need to know to start or enhance your career in web development.

What You Will Learn

  • Structure your code using functions, classes, generics, packages, and libraries
  • Model web applications with domain model frameworks
  • Use the power of modern browsers for processing and storing data
  • Build web games in HTML5 and code them in Dart
  • Get an overview of the available UI and MVC frameworks to use with Dart
  • Build the complex UI needed in business applications with Dart's Polymer framework based on web components
  • Store your data with MongoDB, one of the most popular NoSQL databases, and access your MongoDB databases from Dart
  • 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 If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

    Table of Contents

    1. Learning Dart
      1. Table of Contents
      2. Learning Dart
      3. Credits
      4. About the Authors
      5. About the Reviewers
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. Spiral approach
        2. What this book covers
        3. What you need for this book
        4. Who this book is for
        5. Conventions
        6. Reader feedback
        7. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Dart – A Modern Web Programming Language
        1. What is Dart?
        2. Dart is a perfect fit for HTML5
          1. A very short history of web programming
          2. Dart empowers the web client
          3. JavaScript is not the way to go for complex apps
          4. Google, GWT, and Dart
          5. Advantages of Dart
        3. Getting started with Dart
          1. Installing the Dart Editor
            1. Your first Dart program
        4. Getting a view on the Dart tool chain
          1. The Dart execution model
        5. A bird's eye view on Dart
          1. Example 1 – raising rabbits
            1. Extracting a function
            2. A web version
          2. Example 2 – banking
        6. Making a todo list with Dart
        7. Summary
      9. 2. Getting to Work with Dart
        1. Variables – to type or not to type
        2. Built-in types and their methods
          1. Conversions
          2. Operators
          3. Some useful String methods
          4. Dates and times
          5. Lists
          6. Maps
        3. Documenting your programs
        4. Changing the execution flow of a program
        5. Using functions in Dart
          1. Return types
          2. Parameters
          3. First class functions
        6. Recognizing and catching errors and exceptions
          1. Debugging exercise
        7. Summary
      10. 3. Structuring Code with Classes and Libraries
        1. A touch of class – how to use classes and objects
          1. Visibility – getters and setters
          2. Types of constructors
            1. Named constructors
            2. factory constructors
            3. const constructors
          3. Inheritance
            1. Abstract classes and methods
            2. The interface of a class – implementing interfaces
          4. Polymorphism and the dynamic nature of Dart
          5. Collection types and generics
            1. Typing collections and generics
            2. The collection hierarchy and its functional nature
          6. Structuring your code using libraries
            1. Using a library in an app
            2. Resolving name conflicts
            3. Visibility of objects outside a library
          7. Managing library dependencies with pub
          8. Unit testing in Dart
          9. Project – word frequency
        2. Summary
      11. 4. Modeling Web Applications with Model Concepts and Dartlero
        1. A short introduction to Git and GitHub
          1. Creating a repository on GitHub and a local version
          2. Collaborating on a GitHub project
        2. What a model is and why we need it in programming
        3. Model concepts – a graphical design tool for our models
          1. Working with model concepts
            1. Explaining the model
            2. Drawing the model
            3. Exporting the model
            4. What is JSON?
        4. Dartlero – a simple domain model framework
        5. An example of using Dartlero
        6. The categories and links application
        7. Summary
      12. 5. Handling the DOM in a New Way
        1. Finding elements and changing their attributes
          1. Finding elements
          2. Changing the attributes of elements
        2. Creating and removing elements
        3. Handling events
        4. Manipulating the style of page elements
        5. Animating a game
          1. Ping Pong using style(s)
          2. How to draw on a canvas – Ping Pong revisited
            1. Spiral 1 – drawing a circle and a rectangle
            2. Spiral 2 – colored circles and rectangles
            3. Spiral 3 – moving a ball
            4. Spiral 4 – reorganizing the code
            5. Spiral 5 – a bouncing ball
            6. Spiral 6 – displaying the racket
            7. Spiral 7 – moving the racket using keys
            8. Spiral 8 – moving the racket using the mouse
            9. Spiral 9 – a real game
            10. Spiral 10 – title and replay
            11. Spiral 11 – the master version
        6. Summary
      13. 6. Combining HTML5 Forms with Dart
        1. Spiral 1 – the power of HTML5 forms
        2. Spiral 2 – how to validate data with Dart
          1. Validation in the model
        3. Spiral 3 – how to store data in local storage
        4. Spiral 4 – reading and showing data
        5. Spiral 5 – changing and updating data
        6. Spiral 6 – working with a list of bank accounts
        7. Summary
      14. 7. Building Games with HTML5 and Dart
        1. The model for the memory game
        2. Spiral 1 – drawing the board
        3. Spiral 2 – drawing cells
        4. Spiral 3 – coloring the cells
        5. Spiral 4 – implementing the rules
        6. Spiral 5 – game logic (bringing in the time element)
        7. Spiral 6 – some finishing touches
        8. Spiral 7 – using images
        9. Adding audio to a web page
        10. Using an audio library – Collision clones
        11. Adding video to a web page
        12. Summary
      15. 8. Developing Business Applications with Polymer Web Components
        1. How web components change web development
        2. Web components with Polymer.dart
          1. Declaring and instantiating a web component
        3. Two-way data binding in Polymer.dart
        4. Creating the polymer_links project
          1. Spiral s01
          2. Spiral s02
          3. Spiral s04
          4. Spiral s05
          5. Spiral s06
        5. Using Polymer for the category links project
          1. Adding local storage
        6. Applying web components to the project tasks app
          1. Add and remove Task propagations
        7. Summary
      16. 9. Modeling More Complex Applications with Dartling
        1. The Dartling domain modeling framework
        2. Design of the Travel Impressions model in spirals
        3. Generating Travel Impressions code from the model
        4. Initializing the Travel Impressions model with Data
        5. Testing the Travel Impressions model
        6. Defining and using the MVC pattern
        7. The TodoMVC app
          1. Spiral 0 – generating a class model
          2. Spiral 1 – adding todo tasks
          3. Spiral 2 – showing how many todo tasks left
          4. Spiral 3 – removing a single task and completed tasks
          5. Spiral 4 – editing todos (undo and redo)
          6. Spiral 5 – displaying completed, remaining, or all todos
          7. Spiral 6 – editing a task
        8. Summary
      17. 10. MVC Web and UI Frameworks in Dart – An Overview
        1. DQuery
        2. Bootjack
        3. Dart Web Toolkit (DWT)
          1. The dartling_dwt_todo_mvc_spirals project
        4. Dart widgets
        5. Bee
        6. HTML components
        7. Rikulo UI
          1. Rikulo MVC
        8. Hipster-mvc
        9. Puremvc
        10. StageXL
        11. Flash Professional CC – toolkit for Dart
        12. Angular.dart
        13. Summary
      18. 11. Local Data and Client-Server Communication
        1. The options for browser storage
        2. Asynchronous calls and Futures
        3. Using IndexedDB with Dart
          1. Spiral s00
          2. Spiral s01
          3. Spiral s02
          4. Spiral s03
          5. Spiral s04
          6. Spiral s05
        4. Using Lawndart
        5. A Dart web server
        6. Using JSON web services
          1. Spiral s07
        7. Summary
      19. 12. Data-driven Web Applications with MySQL and MongoDB
        1. Database drivers for Dart
        2. Storing todo data in MySQL
        3. Dartlero tasks – a many-to-many model in MySQL
          1. The JSON storage
          2. MySQL storage
        4. MongoDB – a NoSQL database
        5. Using the mongo_dart driver to store the todo data in MongoDB
        6. Summary
      20. Index