Home Screen

The bulk of the app content for this simple demo is located in lib/home.dart:

The Home class imports a few packages (including the color_panel plugin) and implements a StatefulWidget with backing State, to allow this screen to store and update application state. Dart and Flutter provide great features for managing state using a variety of tools and patterns, the simplest of them being a stateful widget like the one shown in this file.

The properties managed on this widget’s state include a color and counter. The methods _increment and _decrement make use of the setState method to increment or decrement the counter. The _showPanel method requests an instance of ColorPanel from the imported plugin, and then invokes show on it, which will request a native color picker from the operating system. When a color is chosen, setState is used to update the widget’s state with a new color, which will queue it up to be redrawn by the Flutter engine.

The build method for this widget sets up theme and style data and requests the OS name, local hostname, and number of processor cores from Platform class. These could be initialized directly on properties designated as final, or even placed into an external file and used as a service, but for this demo app they’re local variables placed in the widget’s build method for simplicity.