RationalCodec class

A codec for encoding and decoding Rational values to and from strings.

This class provides a single, canonical seam for RationalString conversions at JSON/SQLite/persistence boundaries. It ensures consistent formatting and centralizes parsing logic.

Example:

final encoded = RationalCodec.encode(Rational.fromInt(3, 4));  // "3/4"
final decoded = RationalCodec.decode("3/4");                    // Rational(3, 4)
final safe = RationalCodec.tryDecode("invalid");                // null

Constructors

RationalCodec()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

decode(String value) → Rational
Decodes a string to a Rational.
encode(Rational value) String
Encodes a Rational to its canonical string representation.
tryDecode(String? value) → Rational?
Attempts to decode a string to a Rational.