You are previewing Dart By Example.
O'Reilly logo
Dart By Example

Book Description

Design and develop modern web applications with Google's bold and productive language through engaging example projects

About This Book

  • Full of engaging and varied example projects to equip you to build your own web applications

  • Learn the Dart language and key libraries

  • Productively create fast and reliable web applications

  • Who This Book Is For

    If you are a front- or back-end web developer who is looking to build complex full-featured web applications without the quagmire of disconnected JavaScript frameworks, this book is a practical walkthrough of substantial applications that will have you and your team coding Dart in a productive manner.

    This book will give you a compiled, optional typed, scalable environment to rapidly develop applications. As Dart was designed to be familiar, any developer with even a small amount of knowledge of JavaScript or another programming language will be at home with the language immediately and will be coding quickly.

    What You Will Learn

  • Master the core Dart language, type system, and key development tools

  • Connect to existing web services, process JSON, and create your own framework for the data display

  • Run and debug the Dart server and web applications and compile them in JavaScript

  • Handle form data and encryption

  • Build and deploy server applications on the major OSes and implement the REST API

  • Work with PostgreSQL-an industry standard relational database system

  • Create robust applications with unit tests, documentation, and diagnostic logging

  • Develop command-line applications, and explore the key data structures and libraries

  • In Detail

    Designed to create next generation apps, Google's Dart offers a much more robust framework and also supersedes JavaScript in several aspects. Familiar yet innovative, compact yet scalable, it blows away the accumulated JavaScript legacy limitations. Dart was designed for great tool-ability and developer productivity, allowing you to create better application faster than before. Google chose it for their billion dollar advertising business and you have its power for your projects too.

    This book will introduce you the Dart language starting from its conception to its current form, and where it headed is through engaging substantial practical projects. You will be taken through building typical applications and exploring the exciting new technologies of HTML5.

    With example code projects such as a live data monitoring and viewing system, a blogging system, a slides presentation application, and more, then this book will walk you through step by step through building data-driven web applications with ease and speed.

    Style and approach

    A varied collection of compelling practical Dart projects that are developed progressively with full explanations of concepts and implementation. Each project introduces features of the language and environment, demonstrating how Dart can be used in rich structured web applications.

    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. Dart By Example
      1. Table of Contents
      2. Dart By Example
      3. Credits
      4. About the Author
      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. 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. Starting the Text Editor
        1. Defining Dart
        2. History of Web scripting
        3. The origins of Dart
        4. Downloading the tools
          1. Introducing the WebStorm IDE
          2. Alternative development environments
          3. Help starting a project
          4. Elsewhere in the SDK
        5. Building your first application
          1. Exploring the Web project structure
          2. Unwrapping packages
          3. A look at Pubspec
          4. Putting Dart into the web page
          5. Importing packages
          6. Variable declarations
          7. Writing the event handler
          8. Loading the saved text
          9. Saving the text
          10. Running in the browser
          11. Editing and reloading
          12. Extending the interface
          13. Using the CSS editor
        6. Debugging a Dart application
          1. Working in harmony with JavaScript
          2. Commenting in the code
        7. Summary
      9. 2. Advancing the Editor
        1. The next steps for the text editor
          1. Starting point
            1. Dart classes
          2. Structuring the project
        2. Building the dialog package
          1. The package project structure
          2. Adding a local package reference
            1. Understanding the package scope
            2. Defining the base dialog box
              1. The alert dialog box
              2. The About dialog box
              3. Using the confirmation dialog box
            3. Counting words using a list
            4. The Word Frequency feature
          3. Understanding the typing of Dart code
          4. The file download feature
            1. The clock feature
            2. Executing Dart code
            3. Multi-processing the VM
          5. The class designer
            1. Building a more complicated dialog
            2. Constructing the class
            3. Understanding the flow of events
            4. Launching the application
        3. The command-line app for source code statistics
          1. The command-line project structure
            1. Processing the source code
            2. File handling with the dart:io package
            3. Debugging the command-line program
            4. Integrating the statistics
          2. HTML5 and the canvas
            1. Drawing the pie chart
        4. Building web interfaces with Dart
        5. Compiling to JavaScript
          1. Minification of JavaScript output
        6. Summary
      10. 3. Slideshow Presentations
        1. Building a presentation application
          1. Laying out the application
          2. Defining the presentation format
          3. Parsing the presentation
          4. A sample presentation
          5. Presenter project structures
          6. Launching the application
          7. Building bullet point slides
        2. Accessing private fields
          1. Using true getters and setters
        3. Mixin' it up
          1. Defining the core classes
          2. Transforming data into HTML
          3. Editing the presentation
          4. Displaying the current slide
          5. Navigating the presentation
            1. Handling the button key presses
            2. Using the Function type
            3. Staying within the bounds
            4. Using the slider control
          6. Responding to keyboard events
          7. Showing the key help
            1. Listening twice to event streams
        4. Changing the colors
        5. Adding a date
        6. Timing the presentation
          1. Introducing the Stopwatch class
          2. Implementing the presentation timer
        7. An overview of slides
        8. Handout notes
          1. Comparing optional positional and named parameters
        9. Summary
      11. 4. Language, Motion, and Sound
        1. Going fullscreen
          1. Request fullscreen
          2. Updating the interface for fullscreen
          3. Updating keyboard controls for fullscreen
            1. Adding mouse controls
        2. Adding metadata
          1. Creating a custom annotation
          2. Translating the user interface text
        3. Exploring the intl package
          1. Locating strings to translate
          2. Extracting the strings
            1. Running commands with Dart pub
            2. Obtaining translations
          3. Integrating the translations text
          4. Changing the language of the user interface
          5. Adding a language combo box
        4. Working with dates
          1. Formatting for the locale
        5. Animating slides
          1. Using a timer
        6. Playing sound in the browser
          1. Producing sound effects
          2. Creating sound files
          3. Loading sounds
          4. Playing back sounds
        7. Summary
      12. 5. A Blog Server
        1. The Hello World server example
        2. A blog server
          1. Introducing the HTTP protocol
          2. Starting up the server
          3. Storing the blog posts format
          4. Reading text files
          5. Reading a folder of files
            1. Request handling
            2. Serving text
          6. Robots.txt
          7. Rendering a single blog post
            1. Rendering the index page
            2. Serving images
            3. Locating the file
            4. Serving a single image file
            5. Serving a 404 error
        3. Introducing Dart's server frameworks
          1. Redstone
          2. Rikulo
          3. Shelf
        4. Deployment
          1. Dependencies
          2. Deploying on Unix
          3. Using the screen command
          4. Launching a screen
          5. Deploying on Windows
            1. Using the NSSM tool
            2. Using a Microsoft solution
        5. Load testing
          1. Building a simple load tool
        6. Summary
      13. 6. Blog Server Advanced
        1. Logging
          1. Writing text files
          2. Extracting request information
        2. A blog editor
          1. Password protection
          2. Encryption
          3. Handling more complex forms
          4. Processing the form
          5. Saving data to a disk
            1. Serving a default graphic
            2. Refreshing the blog
        3. Caching
        4. Watching the filesystem
        5. XML feed generation
          1. Serving the RSS
        6. The JSON feed generation
          1. Serving the JSON
          2. Consuming the JSON feed
        7. Static generation
          1. Freezing the website
        8. Introducing the await and async keywords
          1. Joining file paths
          2. Creating an output folder
          3. Generating the front page
            1. Writing the static version
        9. Load testing revisited
          1. Updating the load tester
        10. Summary
      14. 7. Live Data Collection
        1. Kicking off the earthquake monitoring system
        2. Introducing the data source
        3. Exploring the GeoJSON format
          1. Fetching and recording the data
        4. Logging
          1. A simple example of logging
          2. Data monitor logging
        5. Saving to the database
          1. Installing a database system
          2. Using PostgreSQL from Dart
        6. Introducing the pgAdmin GUI
          1. Creating the database and login
          2. Defining the table
          3. Inserting data
          4. Running the program
          5. Maintaining a database
            1. Managing command line arguments
            2. Retrieving data
            3. Deleting data
        7. Observing the Dart VM internals
        8. Unit testing
          1. Running unit tests
          2. Writing unit tests for the data monitor
            1. Grouping tests together
            2. Examining the test results
        9. Summary
      15. 8. Live Data and a Web Service
        1. Freeing the data
          1. Reworking the data collector
          2. Adding a new data table
          3. Filtering the data
          4. Converting the feature to JSON
          5. Improving the data maintenance
          6. Storing the single feature
          7. Running the data application
        2. Creating the web service
          1. Using the package rpc
          2. Initiating the API server
          3. Exposing methods
          4. Error handling of incorrect requests
          5. Serving the latest information
          6. Supplying the data
          7. Discovering the API
          8. Running the web service
        3. Recapping the system so far
        4. Consuming application
          1. Packaging the grid
          2. Initiating the real-time updates
          3. Performing the update
          4. Fetching the JSON
          5. Configuring the grid view control
          6. Formatting the time
          7. Working with date and time
          8. Building the table
          9. Showing the page
        5. Summary
      16. 9. A Real-Time Visualization
        1. Iteration overview
        2. Application overview
          1. Drawing the map image
          2. Plotting on the map
          3. Animating the display
          4. Fetching the data
          5. Updating the map indicators
          6. Mouse over popups
          7. Zooming into the display
        3. Notifying the user of an update
        4. Plotting the user's location
        5. Sorting the feature list
        6. Documenting Dart code with dartdoc
        7. Summary
      17. 10. Reports and an API
        1. Recapping the earthquake system
        2. Advancing the REST API
        3. Passing parameters to the API
        4. Posting on the API
          1. Connecting to an API client
          2. Varying the data
          3. Returning to the map
          4. Reporting on the data
          5. The ReportSite project
          6. Report classes
          7. Creating a printable report
          8. Charting the data
          9. Exporting to CSV
        5. Summary
      18. Index