Chapter 56 — Calculator
Part 1C — Eight mini-projects · Chapter 56 of 62 · 12 h
Chapter 56 — Calculator
Level: intermediate Estimated time: 12 h Prerequisites: chapters 08, 09, 13, 16 (Dart) and 45, 46, 48, 49, 51 (Flutter), plus chapter 55 (project 1) What you'll be able to do by the end: write a Flutter app whose business core is a pure Dart class, unit-tested, and whose UI is nothing more than a display layer plugged into it.
56.0 — Chapter objectives
By the end of this chapter, you will be able to:
- turn a specification into a state machine before writing a single line of code;
- isolate the business logic in a Dart class with no
import 'package:flutter/...'at all; - model digit-by-digit number entry, including the decimal separator;
- chain operations like a real pocket calculator, and handle repeated
=,C,CE, the sign, and the percentage; - throw and catch a domain exception (
DivisionParZeroException); - format a
doublefor human display: thousands separator, decimal comma, scientific notation; - keep text that is too long from overflowing the screen with
FittedBox; - build a button grid with
RowandExpanded, withoutGridView; - write a reusable button widget, parameterized by an
enumand colored by theColorScheme; - produce a proper press effect with
Material+InkWell; - wire the logic to the UI with a single
setState, and display a history in aListView; - accept the physical keyboard with
KeyboardListenerandLogicalKeyboardKey; - write unit tests for the logic that run without an emulator.
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion