O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mastering Dart

Book Description

Master the art of programming high-performance applications with Dart

In Detail

Starting with a discussion about the basic features of Dart, we will dive into the more complicated concepts such as generics, annotation with reflection, errors and exceptions, which will help us improve our code. Moving on, you will learn how and when to create objects and also advanced techniques that will help you execute asynchronous code. You will also learn about the collection framework and how to communicate with the different programs written in JavaScript using Dart.

This book will show you how to add internalization support to your web applications and how i18n and l10n access can be embedded into your code to design applications that can be localized easily. You will be shown how to organize client-to-server communication and how different HTML5 features can be used in Dart. Finally, this book will show you how you can store data locally, break the storage limit, and prevent security issues in your web application.

What You Will Learn

  • Build applications easily using the event-driven paradigm
  • Familiarize yourself with asynchronous programming
  • Understand when and how to use collections to store and manipulate groups of objects
  • Use Dart and JavaScript together to build web applications
  • Add internalization and localization support to your application to improve its performance
  • Organize client-to-server communication and discover the protocols for specific scenarios
  • Detect and use HTML5 features that will help you deliver rich, cross-platform content
  • Discover different techniques to secure your web application from unauthorized users

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. Mastering Dart
    1. Table of Contents
    2. Mastering Dart
    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. Beyond Dart's Basics
      1. Modularity and a namespace
        1. Modularity in software development
        2. Modularity in Dart
        3. Libraries
      2. Functions and closures in different scopes
        1. Naming functions with a variable
        2. Passing a function as an argument to another function
        3. Returning a function as a result of another function
        4. Storing a function in data structures
        5. Closures
      3. Classes and mixins
        1. Types
        2. Classes
        3. Inheritance
        4. Interface
        5. Mixins
        6. Well-designed classes
        7. To be private or not
        8. Variables versus the accessor methods
        9. Inheritance versus composition
      4. Methods and operators
        1. Checking the values of the parameters before using them
        2. Well-designed methods
      5. Summary
    9. 2. Advanced Techniques and Reflection
      1. Generics
        1. Raw types
        2. Using generics
        3. Generic types
        4. Generic functions
      2. Errors versus exceptions
        1. Errors
        2. Exceptions
      3. Annotations
        1. Built-in annotations
          1. Deprecated
          2. Override
          3. Proxy
        2. Custom annotations
      4. Reflection
        1. Introspection in action
        2. Reflection in action
      5. Summary
    10. 3. Object Creation
      1. Creating an object
        1. A generative constructor
        2. A constructor with optional parameters
        3. A named constructor
        4. A redirecting constructor
        5. A private constructor
        6. A factory constructor
          1. The factory method design pattern
          2. The singleton design pattern
        7. A constant constructor
        8. Initializing variables
        9. Syntactic sugar
          1. Method call
          2. Cascade method invocation
      2. Summary
    11. 4. Asynchronous Programming
      1. Call-stack architectures versus event-driven architectures
        1. Call-stack architectures
        2. Event-driven architectures
        3. The Dart VM execution model
        4. Synchronous versus Asynchronous code
      2. Future
        1. Future and Timer
        2. Future and Microtask
        3. Sync the Future class
        4. Future with a value
        5. Future with an error
        6. Delaying the Future class
      3. Zones
        1. Simple zone example
        2. Zone nesting
        3. Zone values
        4. Zone specifications
        5. Interaction between zones
        6. Tracking the zone execution
      4. Isolates
      5. Summary
    12. 5. The Stream Framework
      1. Why you should use streams
      2. Single-subscription streams versus broadcast streams
        1. A single-subscription stream
        2. A broadcast stream
      3. An overview of the stream framework API
        1. The Stream class
        2. The validation methods of the Stream class
        3. The search methods of the Stream class
        4. The subset methods of the Stream class
        5. Creating a stream
        6. A new stream from the Future class
        7. A new stream from the Iterable class
        8. A new stream with periodically generated events
        9. A new stream from the transformation pipe
        10. A new stream from StreamController
        11. What does the StreamSubscription class do?
        12. Minimizing access to the Stream class members using StreamView
        13. The Sink and EventSink interfaces
        14. Importance of the StreamConsumer interface
        15. What does the StreamSink class do?
        16. Transforming streams with the StreamTransformer class
        17. Traverse streams with StreamIterator
      4. Summary
    13. 6. The Collection Framework
      1. A Dart collection framework
      2. Ordering of elements
        1. The Comparable interface
        2. The Comparator type
      3. Collections and generics
      4. The collection class hierarchy
      5. The Iterable interface
        1. Properties of the Iterable collection
        2. Checking the items of a collection on a condition
        3. The iterate over collection
        4. The search over collection
        5. Creating a new collection
        6. Reducing a collection
        7. Converting a collection
        8. Generating a collection
        9. The Lazy Iterable
      6. The Iterable interface
      7. BidirectionalIterator
      8. The collection classes
        1. List
        2. LinkedList
        3. Set
          1. HashSet
          2. LinkedHashSet
          3. SplayTreeSet
        4. Queue
        5. Map
          1. HashMap
          2. LinkedHashMap
          3. SplayTreeMap
      9. Unmodifiable collections
        1. The unmodifiable list
        2. The unmodifiable map
      10. Choosing the right collection
      11. Summary
    14. 7. Dart and JavaScript Interoperation
      1. Interoperation at a glance
      2. The dart:js library
        1. JsObject
        2. JsFunction
        3. JsArray
      3. Type conversion
        1. Direct type conversion
        2. Proxy type conversion
        3. Collection conversion
      4. JsObject and instantiation
      5. JsFunction and the this keyword
      6. Dart with jQuery
        1. How to create a shortcut to jQuery
        2. Why does JProxy need a method call?
        3. How does JProxy invoke jQuery?
        4. An example project
        5. How to get the jQuery version
        6. How to perform actions in jQuery
        7. How to use effects in jQuery
        8. What is the impact on performance?
      7. Summary
    15. 8. Internalization and Localization
      1. The key principles
        1. Executable code versus User Interface
          1. Numbers and dates
          2. Messages
          3. Measuring units and currencies
          4. Text input and layout
          5. Formatting date and time
      2. The Intl library
        1. Changing a locale
        2. Formatting numbers
        3. Formatting dates
        4. Internalizing messages
        5. Adding parentheses
        6. Adding gender
        7. Adding select
        8. Creating complex message translations
        9. Bidirectional formatting
      3. Internationalizing your web application
      4. Extracting messages
      5. Using Google Translator Toolkit
      6. Using translated messages
      7. Summary
    16. 9. Client-to-server Communication
      1. Communication at a glance
        1. The Internet protocol stack
      2. Hypertext Transfer Protocol
        1. Web server
        2. Standalone HTTP communication via the dart:io library
        3. Standalone HTTP communication via the http package
        4. Web browser HTTP communication via the dart:html library
        5. Web browser HTTP communication via the http package
      3. AJAX polling request
      4. AJAX long polling request
        1. Server-Sent Events
      5. WebSocket
      6. Summary
    17. 10. Advanced Storage
      1. Cookies
      2. Web Storage
        1. The Session storage
        2. The Local storage
      3. Web SQL
      4. IndexedDB
      5. Summary
    18. 11. Supporting Other HTML5 Features
      1. The notification APIs
        1. When to notify
        2. Preventing repeated notifications
      2. The native drag-and-drop APIs
        1. Draggable content
        2. The drag-and-drop events
        3. Dragging data
        4. Dragging the feedback image
        5. Dragging effects
        6. The drop target
        7. Finishing a drop
        8. Finishing a drag
      3. The geolocation APIs
        1. Determining the current location
        2. Geolocation on maps
        3. Tracking the present location
      4. Canvas
        1. Example – the canvas editor
          1. Beginning with HTML
          2. Moving to the main function
          3. The CanvasWidget component
          4. The ToolSelector widget
          5. The ColorSelector widget
          6. The Tool class
          7. The Pen tool
          8. The Line tool
          9. The Rectangle tool
          10. The Oval tool
          11. How to clear the context
          12. How to preview the context
      5. Summary
    19. 12. Security Aspects
      1. Web security
        1. Transport Layer Security and Secure Socket Layer at a glance
        2. The TLS certificate
      2. Securing a server
      3. Securing a client
        1. Attributes of cookies
        2. HTTP Strict Transport Security
        3. Content Security Policy
        4. Cross Origin Resource Sharing versus JSON with padding
        5. CAPTCHA
      4. Security best practices
      5. Summary
    20. Index