Unit Converter

Loading preview

Starting the Flutter app

Multi-category unit converter with length, weight, temperature, and more

Get the source

Add it to your project

Copies the Dart source into your app, so you own it. Flutter SDK only, no extra packages.

First time? Run dart pub global activate fluttertemplates_dev, or read the CLI guide.

How it works

_categories stores each unit’s factor to a base unit as a string, and _getConversionResult converts by multiplying then dividing. Temperature bypasses that through _convertTemperature, going via Celsius; its toBase values are unused placeholders. Unparseable input counts as 0. The Quick Conversions rows only print two unit names, with no values or tap action, and _inputController isn’t disposed.

Adapting it

  • Store factors as double in a unit class, removing double.parse.
  • Use TextInputType.numberWithOptions(signed: true, decimal: true) so negatives and decimals are reachable.
  • Make _buildQuickConversion tappable to set _fromIndex and _toIndex.