tryParse static method
Parses a string containing a fraction or a mixed fraction into a number.
If the parsing fails, this method returns null
. For example:
Rational.tryParse('1/2') // Fraction(1, 2);
Rational.tryParse('2 5/3') // MixedFraction(2, 5, 3);
Rational.tryParse('') // null
Implementation
static Rational? tryParse(String value) {
if (value.isFraction) {
return Fraction.fromString(value);
}
if (value.isMixedFraction) {
return MixedFraction.fromString(value);
}
return null;
}