Chapter 57 — Unit Converter
Part 1C — Eight Mini-Projects · Chapter 57 of 62 · 12 h
Chapter 57 — Unit Converter
Level: intermediate Estimated time: 12 h Prerequisites: chapter 56 — Project 2: the calculator What you will be able to do by the end: build a complete form-driven application, cleanly separate testable business logic from its interface, and write the unit tests that prove your calculations are correct.
57.0 — Chapter Objectives
By the end of this chapter, you will be able to:
- model a business domain with an enhanced
enumand a value class; - explain what a pivot unit is and why it cuts the work by a factor of a hundred;
- demonstrate why temperature cannot be converted with a simple factor;
- generalize a "factor" model into a "pair of functions" model;
- write a pure conversion function with no dependency on Flutter;
- wire a
TextFieldto aTextEditingControllerand react to every keystroke; - restrict input to numeric characters with
inputFormatters; - distinguish what an
inputFormatterfilters from whatdouble.tryParsevalidates; - handle the French decimal comma and grouping spaces;
- build two synchronized
DropdownButton<Unite>widgets; - filter the list of units by the selected category with
where; - swap the source and target units in a single
setStatecall; - convert in real time via
onChangedwith no "Calculate" button; - format a readable result with
NumberFormatfrom theintlpackage; - choose a number of decimal places suited to the order of magnitude of the result;
- switch to scientific notation for extreme numbers;
- organize six categories into tabs with
TabControllerandTabBarView; - preserve the state of each tab with
AutomaticKeepAliveClientMixin; - keep a history of confirmed conversions;
- persist the user's last choice with
shared_preferences; - write a suite of unit tests that verifies each family of conversions.
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion