StringToDurationConverter class

A utility to safely parse a string into a Duration.

This class handles various time formats commonly used to represent durations, such as HH:MM:SS. It is used by creating an instance with the input string and then calling the toDurationOrNull method.

{@tool snippet}

final duration = const StringToDurationConverter('01:30:45').toDurationOrNull();
print(duration); // Prints: 1:30:45.000000

final invalid = const StringToDurationConverter('not a duration').toDurationOrNull();
print(invalid); // Prints: null

{@end-tool}

Annotations
  • @Deprecated('May be removed from package in the future!')

Constructors

StringToDurationConverter.new(String? input)
Creates a converter for the given string input.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
input String?
The string to be converted into a Duration.
final
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
toDurationOrNull() Duration?
Tries to convert the stored input string to a Duration.
toString() String
A string representation of this object.
inherited

Operators

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