A unit converter looks like a weekend project until the details arrive. One kilogram is 2.20462 pounds, but a careless double conversion can show 2.2046200000000003. Temperature does not convert with a simple multiplier at all. Currency rates go stale. Users search by typing half a word, pin the three tools they use daily, and expect the last conversion to still be there when they reopen the app on a plane with no signal.

This guide explains how to build a Flutter unit converter that stays accurate and fast at scale, using the same architecture behind Calculator: All Unit Converter, an offline app with 87 unit categories, 537 units, a currency converter for 30 currencies, a scientific calculator, and 68 additional calculators and tools. The patterns below cover the data model, exact arithmetic, temperature handling, offline currency, and the search and history experience that makes hundreds of tools feel simple.

How should you model units in Flutter?

Model every unit as a conversion to one base unit in its category, so a category with N units needs N factors instead of N squared pairwise formulas. Length uses the meter as its base, mass uses the kilogram, and volume uses the liter. Converting from unit A to unit B then becomes two steps: multiply by the factor from A to the base, then divide by the factor from B to the base. Adding a new unit means adding one row of data, not touching conversion code, which is how a catalog grows to 537 units without the logic growing with it.

class UnitDef { const UnitDef({ required this.id, required this.name, required this.symbol, required this.toBase, // multiply a value in this unit to get base units }); final String id; final String name; final String symbol; final double toBase; } class UnitCategory { const UnitCategory({ required this.id, required this.name, required this.units, }); final String id; final String name; final List<UnitDef> units; } const lengthCategory = UnitCategory( id: 'length', name: 'Length', units: [ UnitDef(id: 'meter', name: 'Meter', symbol: 'm', toBase: 1), UnitDef(id: 'kilometer', name: 'Kilometer', symbol: 'km', toBase: 1000), UnitDef(id: 'centimeter', name: 'Centimeter', symbol: 'cm', toBase: 0.01), UnitDef(id: 'mile', name: 'Mile', symbol: 'mi', toBase: 1609.344), UnitDef(id: 'foot', name: 'Foot', symbol: 'ft', toBase: 0.3048), UnitDef(id: 'inch', name: 'Inch', symbol: 'in', toBase: 0.0254), ], ); double convert(double value, UnitDef from, UnitDef to) { final baseValue = value * from.toBase; return baseValue / to.toBase; } 

Keep the catalog as plain Dart data, grouped by category, with a stable string id for every unit. Stable ids matter because history entries, pinned tools, and saved favorites all reference units by id; renaming a display name later must not break stored data. The same discipline applies in form validation that scales: separate the data and rules from the widgets, and the UI stays small while the catalog grows.

Why does floating point break conversions, and what fixes it?

Floating point breaks conversions because Dart doubles store decimal factors as binary approximations, so repeated multiplication and division accumulate visible error in the result. The fix for exactness is fraction arithmetic: store each conversion factor as a numerator and denominator pair of integers, do the math with BigInt, and only convert to a decimal string at display time. Many everyday factors are exact fractions by definition — one inch is exactly 25.4 millimeters, one pound is exactly 0.45359237 kilograms — so fractions preserve the true value instead of an approximation of it.

class Fraction { Fraction(BigInt numerator, BigInt denominator) : numerator = numerator ~/ _gcd(numerator, denominator), denominator = denominator ~/ _gcd(numerator, denominator); factory Fraction.fromDecimal(String text) { final negative = text.startsWith('-'); final clean = negative ? text.substring(1) : text; final parts = clean.split('.'); final whole = parts.first; final decimals = parts.length > 1 ? parts[1] : ''; final scale = BigInt.from(10).pow(decimals.length); var value = BigInt.parse(whole) * scale; if (decimals.isNotEmpty) value += BigInt.parse(decimals); return Fraction(negative ? -value : value, scale); } final BigInt numerator; final BigInt denominator; static BigInt _gcd(BigInt a, BigInt b) { var x = a.abs(); var y = b.abs(); while (y != BigInt.zero) { final t = x % y; x = y; y = t; } return x == BigInt.zero ? BigInt.one : x; } Fraction operator *(Fraction other) => Fraction(numerator * other.numerator, denominator * other.denominator); Fraction operator /(Fraction other) => Fraction(numerator * other.denominator, denominator * other.numerator); double toDouble() => numerator.toDouble() / denominator.toDouble(); String toDecimalString({int maxDecimals = 10}) { final value = toDouble(); var text = value.toStringAsFixed(maxDecimals); text = text.replaceFirst(RegExp(r'0+$'), ''); text = text.replaceFirst(RegExp(r'\.$'), ''); return text.isEmpty ? '0' : text; } } 

With fractions, converting 1 inch to millimeters computes 254/10 exactly, and converting back returns exactly 1 instead of 0.9999999999. Use fractions for the stored factors and the arithmetic, then format once for display with a sensible number of decimals and thousands separators. Rounding belongs at the very end of the pipeline, never in the middle, because rounding an intermediate value compounds into the final answer. The Calculator app uses exact fraction math for this reason: a converter that shows trailing noise digits loses user trust immediately, even when the underlying value is nearly right.

Approach Accuracy Cost Best for
double factors Binary approximation, visible noise after chained math Fastest, simplest Quick prototypes and rough estimates
Fraction factors with BigInt Exact for factors that are exact by definition Slightly more code, still instant on a phone Published converters where displayed digits must be trustworthy
Decimal package Exact decimal arithmetic Extra dependency Money math where decimal rounding rules are specified

How do you convert temperature in Flutter?

Convert temperature with an offset formula instead of a multiplier, because Celsius, Fahrenheit, and Kelvin have different zero points. The reliable pattern is to convert every input to Kelvin first, then convert Kelvin to the target scale. Celsius to Kelvin adds 273.15. Fahrenheit to Kelvin subtracts 32, multiplies by 5/9, then adds 273.15. Reversing those steps converts Kelvin back to either scale, and the two-step structure keeps every pair correct with only four small functions.

double toKelvin(double value, String scale) { switch (scale) { case 'celsius': return value + 273.15; case 'fahrenheit': return (value - 32) * 5 / 9 + 273.15; case 'kelvin': return value; default: throw ArgumentError('Unknown temperature scale: $scale'); } } double fromKelvin(double kelvin, String scale) { switch (scale) { case 'celsius': return kelvin - 273.15; case 'fahrenheit': return (kelvin - 273.15) * 9 / 5 + 32; case 'kelvin': return kelvin; default: throw ArgumentError('Unknown temperature scale: $scale'); } } double convertTemperature(double value, String from, String to) { return fromKelvin(toKelvin(value, from), to); } 

Treat temperature as a special category in the catalog: flag it as offset-based so the generic multiplier path never touches it. Validate the input as well, because a Kelvin value below zero is physically impossible, and a converter that happily converts -500 Kelvin teaches users not to trust the app. Small correctness details like this are the difference between a demo and a tool people keep on their home screen.

How do you handle currency conversion offline?

Handle currency offline by caching the last successfully loaded exchange rates on the device and converting from the cache when there is no connection. Currency is the one category that cannot be fully static, because rates change daily. The Calculator app bases its 30-currency converter on European Central Bank reference rates and keeps the last loaded rates available offline, so conversion still works on a plane while the interface can show when the rates were last updated. The pattern is: fetch when online, persist the rates with a timestamp, and always read from the local copy for conversion.

class CachedRates { const CachedRates({required this.rates, required this.fetchedAt}); final Map<String, double> rates; // units per 1 EUR, ECB style final DateTime fetchedAt; double convert(double amount, String from, String to) { final fromRate = rates[from]; final toRate = rates[to]; if (fromRate == null || toRate == null) { throw ArgumentError('Missing rate for $from or $to'); } return amount / fromRate * toRate; } bool get isStale => DateTime.now().difference(fetchedAt) > const Duration(hours: 24); } 

Show the rate date in the interface whenever rates are stale, and never silently present an old rate as a live one. Offline-first design with honest freshness labels is the same principle behind privacy-first offline apps: the app works without a network or an account, and the user can see exactly what state the data is in. Persist the cache with a simple key-value store or a local database, and refresh it opportunistically on launch when a connection exists.

How do you make 500+ tools easy to find?

Make hundreds of tools findable with one search bar over every category, unit, and calculator, plus pinned favorites and a searchable history. Nobody browses 87 categories by scrolling. The Calculator app puts a single search field across all converters and calculators, lets users pin the tools they use daily, and keeps a 200-item searchable history with copy and share on every result. Search should match unit names, symbols, and category names, so typing kg, kilo, or weight all land on the mass converter.

List<UnitDef> searchUnits(String query, List<UnitCategory> catalog) { final needle = query.trim().toLowerCase(); if (needle.isEmpty) return const []; final results = <UnitDef>[]; for (final category in catalog) { for (final unit in category.units) { final haystack = '${unit.name} ${unit.symbol} ${category.name}'.toLowerCase(); if (haystack.contains(needle)) results.add(unit); } } return results; } 

Rank exact symbol matches first, then name-prefix matches, then substring matches, so the most likely tool is always at the top. Keep the conversion screen itself minimal: one input field, two unit selectors with a swap button, and the result updating on every keystroke. Layout discipline matters on small phones and tablets alike, and the techniques in responsive design for every screen keep the keypad and result readable without overflow. Store history as structured entries — input value, from unit id, to unit id, result, timestamp — so a history row can reopen the exact conversion with one tap.

What else belongs in a converter app?

A converter app earns daily use when the scientific calculator and the common one-off calculators sit beside the units, all working offline with no account. Beyond unit conversion, the Calculator app includes a scientific calculator with trigonometry, logarithms, roots, powers, and constants in degrees or radians, plus 68 calculators and tools spanning finance, business, math, geometry, electronics, and date and time — loans, mortgages, percentages, and Ohm's law among them. Each calculator is a small form with validated inputs and one clear result, which keeps the code uniform: parse, validate, compute, format, save to history.

Build each calculator as a pure function over parsed numbers, separate from its widget. A loan payment function that takes principal, annual rate, and months can be unit-tested in milliseconds, and the widget only collects inputs and renders the answer. Shared building blocks — a numeric input field with validation, a result card with copy and share, and the history writer — mean the 68th calculator costs a fraction of the first one. That reuse is what makes a broad tool catalog maintainable by one developer instead of becoming 68 separate maintenance burdens.

Putting it together

A Flutter unit converter that people trust rests on four decisions: model units as factors to a base unit so the catalog scales by data, use exact fraction arithmetic so displayed digits are correct, special-case temperature with offset formulas through Kelvin, and cache currency rates with an honest freshness label so everything works offline. Add one search bar, pinned favorites, and a structured history, and hundreds of tools feel like one simple app. The full result is the Calculator: All Unit Converter case study.

Building a utility app that needs this level of correctness and offline reliability? Get in touch and let's talk about your project.

Originally published at uzairxdev.online