Converter class
Fluent wrapper that offers composable access to conversion helpers.
Constructors
- Converter(Object? _value, {Object? defaultValue, DynamicConverter? customConverter})
-
Creates a converter around
_valuewith optional fallbacks or custom pre-processing.const
Properties
Methods
-
fromList(
int index) → Converter -
Reads a nested value from a list (or JSON string list) using
index. -
fromMap(
Object? key) → Converter -
Reads a nested value from a map (or JSON string map) using
key. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
to<
T> () → T -
Converts the wrapped value to
T, throwing when conversion fails. -
toBigInt(
) → BigInt - Converts to BigInt, mirroring Convert.toBigInt.
-
toBigIntOr(
BigInt defaultValue) → BigInt -
Converts to BigInt, falling back to
defaultValueon failure. -
toBool(
) → bool - Converts to bool, mirroring Convert.toBool.
-
toBoolOr(
bool defaultValue) → bool -
Converts to bool, falling back to
defaultValueon failure. -
toDateTime(
) → DateTime - Converts to DateTime, mirroring Convert.toDateTime.
-
toDateTimeOr(
DateTime defaultValue) → DateTime -
Converts to DateTime, falling back to
defaultValueon failure. -
toDouble(
) → double - Converts to double, mirroring Convert.toDouble.
-
toDoubleOr(
double defaultValue) → double -
Converts to double, falling back to
defaultValueon failure. -
toInt(
) → int - Converts to int, mirroring Convert.toInt.
-
toIntOr(
int defaultValue) → int -
Converts to int, falling back to
defaultValuewhen conversion fails. -
toList<
T> ({DynamicConverter< T> ? elementConverter}) → List<T> - Converts to List, optionally transforming each item.
-
toMap<
K, V> ({DynamicConverter< K> ? keyConverter, DynamicConverter<V> ? valueConverter}) → Map<K, V> - Converts to Map, allowing converters for keys and values.
-
toNum(
) → num - Converts to num, mirroring Convert.toNum.
-
toNumOr(
num defaultValue) → num -
Converts to num, falling back to
defaultValueon conversion failure. -
toOr<
T> (T defaultValue) → T -
Converts to
T, returningdefaultValuewhen conversion throws. -
toSet<
T> ({DynamicConverter< T> ? elementConverter}) → Set<T> - Converts to Set, optionally transforming each item.
-
toString(
) → String -
Converts to String, mirroring Convert.toString.
override
-
toStringOr(
String defaultValue) → String -
Converts to String, falling back to
defaultValuewhen conversion fails. -
toUri(
) → Uri - Converts to Uri, mirroring Convert.toUri.
-
toUriOr(
Uri defaultValue) → Uri -
Converts to Uri, falling back to
defaultValueon failure. -
tryTo<
T> () → T? -
Attempts to convert to
T, returningnullon failure. -
tryToBigInt(
) → BigInt? - Converts to BigInt without throwing, mirroring Convert.tryToBigInt.
-
tryToBool(
) → bool? - Converts to bool without throwing, mirroring Convert.tryToBool.
-
tryToDateTime(
) → DateTime? - Converts to DateTime without throwing, mirroring Convert.tryToDateTime.
-
tryToDouble(
) → double? - Converts to double without throwing, mirroring Convert.tryToDouble.
-
tryToInt(
) → int? - Converts to int without throwing, mirroring Convert.tryToInt.
-
tryToList<
T> ({DynamicConverter< T> ? elementConverter}) → List<T> ? -
Converts to List without throwing, returning
nullwhen conversion fails. -
tryToMap<
K, V> ({DynamicConverter< K> ? keyConverter, DynamicConverter<V> ? valueConverter}) → Map<K, V> ? -
Converts to Map without throwing, returning
nullon failure. -
tryToNum(
) → num? - Converts to num without throwing, mirroring Convert.tryToNum.
-
tryToSet<
T> ({DynamicConverter< T> ? elementConverter}) → Set<T> ? -
Converts to Set without throwing, returning
nullon failure. -
tryToString(
) → String? - Converts to String without throwing, mirroring Convert.tryToString.
-
tryToUri(
) → Uri? - Converts to Uri without throwing, mirroring Convert.tryToUri.
-
withConverter(
DynamicConverter converter) → Converter -
Returns a new Converter that applies
converterbefore any lookup. -
withDefault(
Object? value) → Converter -
Returns a new Converter that uses
valuewhenever a conversion fails.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited