Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

DartbeginnercliAI generated

CLI Unit & Currency Converter

Build a command-line converter in Dart for units and currencies. You run it like this: convert 5 --from km --to mi, or convert 100 --from EUR --to USD, and it prints the result. It supports length, weight, temperature and a handful of currencies using a fixed table of exchange rates, and refuses conversions that make no sense, such as kilograms to meters. It's a good first Dart project: you'll learn functions, maps, enums and switch statements, reading command-line options with the args package, handling errors, and writing unit tests.

Estimate
~8h
Steps
6
Completed by
0
Proposed by
codeseed.app

Dart SDK · args package

Project roadmap

  1. 01

    Create the project

    ~1h

    Install the Dart SDK and create a project with dart create -t console converter. Add the args package with dart pub add args, and test as a dev dependency. Replace the default code with a main function that prints the arguments it received. Done when: dart run bin/converter.dart 5 prints the argument.

  2. 02

    Read the options with args

    ~1.5h

    Use ArgParser to define --from, --to (both required) and --help, and read the value to convert as the first positional argument. Parse the value with double.tryParse. Print the usage text and exit with code 64 for missing or invalid input. Done when: valid arguments are read correctly, and invalid ones print the usage.

  3. 03

    Convert length, weight and temperature

    ~2h

    Define a Category enum (length, weight, temperature, currency) and a map from each unit to its category. For length and weight, store how much each unit is worth in a base unit (meters, kilograms) and convert through it. Temperature needs formulas, so convert through Celsius. Throw a clear error when the two units aren't in the same category. Done when: 5 km to mi gives 3.11, and 100 °C to °F gives 212.

  4. 04

    Convert currencies

    ~1h

    Add a map of exchange rates relative to EUR for at least 6 currencies (for example USD, GBP, JPY, CHF and RON), with a comment showing the date the rates are from. Convert through EUR, round money to 2 decimals, and mention in the output that the rates are fixed and not live. Done when: currency conversions work in both directions and match a manual calculation.

  5. 05

    Format the output and list units

    ~1h

    Print results like 5 km = 3.11 mi, choosing a sensible number of decimals. Add a --list option that prints every supported unit grouped by category. Make unit names case-insensitive (KM, km and Km all work). Done when: the output is clean, and --list shows every unit.

  6. 06

    Write unit tests

    ~1.5h

    With package:test, write tests for every category, a round trip (converting and converting back returns the original value), zero and negative values (including temperatures below zero), mixing categories (which must throw an error) and unknown units. Done when: dart test passes.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~8h · 6 steps

Tech stack

Dart SDKargs package