tryFromString static method
Attempts to parse a string into a Rational object.
This method uses fromString to parse the input string. If parsing fails,
or if the input string is null, it returns null instead of
throwing an exception.
Example:
print(RationalParsing.tryFromString("1 3/4")); // Outputs: 7/4
print(RationalParsing.tryFromString("invalid")); // Outputs: null
print(RationalParsing.tryFromString(null)); // Outputs: null
value: The string to attempt to parse into aRational. Can benull.- Returns: A
Rationalobject if parsing is successful, ornullif parsing fails or the input isnull.
Implementation
static Rational? tryFromString(String? value) {
if (value == null) {
return null;
}
try {
return fromString(value);
} catch (e) {
return null;
}
}