Skip to content
pubscout

fraction

6.0.1, released 7 days ago by fluttercompletereference.com

Create, parse, and perform arithmetic operations with fractions and mixed fractions.

WASM-ready
$ flutter pub add fraction
Source repository

What it does

Provides immutableFraction and MixedFraction classes to represent numbers as fractions. Supports arithmetic, conversions to doubles/strings/Unicode glyphs, and Egyptian fraction expansions.

AI-written summary of version 6.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need exact rational number arithmetic without floating-point inaccuracies.
  • You want to parse fraction strings or convert doubles to fraction approximations.
  • You need to compute Egyptian fraction expansions.

Skip it when

  • You are performing heavy scientific calculations that rely natively on floating-point primitives.

Strengths

  • Immutable types ensuring safe state management.
  • Supports both regular and mixed fractions along with rational parsing.
  • Built-in arithmetic operations that reduce to lowest terms.

Weaknesses

  • Arithmetic operations throw a FractionException if results overflow the integer range.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
0
final f1 = Fraction(5, 7);
final f2 = Fraction(1, 5);
final sum = f1 + f2; // 32/35

Alternatives

Packages that do the same job and could replace fraction.

  • flutter_flavorizr

    A utility to easily create and configure application flavors in Flutter.

  • validators2

    String validation and sanitization for Dart.

  • string_to_color

    Convert strings to colors, hex strings, or hex integers in Dart and Flutter.

  • hex

    Provides simple HEX.encode and HEX.decode functions for converting between byte lists and hexadecimal strings.

Works with

Packages commonly used together with fraction: ones it builds on, ones built on it, and its own family.