Chapter 3. Building and testing your own Dart app

 

This chapter covers

  • Building a user interface in the browser
  • Reacting to user events
  • Reusing code with functions
  • Getting familiar with Dart classes
  • Writing simple unit tests

It’s time to get your hands on some real Dart code. Using the core language constructs of variables, functions, and classes, you’ll build a simple browser-based packing-list app called PackList to let users keep track of things to take on their vacations. One of Dart’s design goals is to be familiar; this chapter should help you feel comfortable with the Dart functionality around variables, functions, and classes before we get to the more surprising and interesting features in later chapters.

Instead of building the simple user interface in raw HTML, you’ll build it using Element classes from the built-in dart:html library. At the time of writing, no GUI or widget library is available as part of the Dart SDK, although various open source third-party libraries are in development. It’s the Dart development team’s goal to make Dart a “batteries included” solution, and a UI library will eventually be included in the SDK. For now, though, you can build user interfaces by manipulating HTML elements in Dart code; knowledge of how to do this will also help you when a UI library does appear, because you’ll be more confident with the underlying mechanisms behind the widgets.

3.1. Building a UI with dart:html

3.2. Building interactivity with browser events

3.3. Wrapping structure and functionality with classes

3.4. Unit-testing the code

3.5. Summary

sitemap