Converter class

Fluent wrapper that offers composable access to conversion helpers.

Constructors

Converter(Object? _value, {Object? defaultValue, DynamicConverter? customConverter})
Creates a converter around _value with optional fallbacks or custom pre-processing.
const

Properties

decoded Converter
Decodes JSON string input before continuing conversions.
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

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 defaultValue on failure.
toBool() bool
Converts to bool, mirroring Convert.toBool.
toBoolOr(bool defaultValue) bool
Converts to bool, falling back to defaultValue on failure.
toDateTime() DateTime
Converts to DateTime, mirroring Convert.toDateTime.
toDateTimeOr(DateTime defaultValue) DateTime
Converts to DateTime, falling back to defaultValue on failure.
toDouble() double
Converts to double, mirroring Convert.toDouble.
toDoubleOr(double defaultValue) double
Converts to double, falling back to defaultValue on failure.
toInt() int
Converts to int, mirroring Convert.toInt.
toIntOr(int defaultValue) int
Converts to int, falling back to defaultValue when 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 defaultValue on conversion failure.
toOr<T>(T defaultValue) → T
Converts to T, returning defaultValue when 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 defaultValue when conversion fails.
toUri() Uri
Converts to Uri, mirroring Convert.toUri.
toUriOr(Uri defaultValue) Uri
Converts to Uri, falling back to defaultValue on failure.
tryTo<T>() → T?
Attempts to convert to T, returning null on 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 null when conversion fails.
tryToMap<K, V>({DynamicConverter<K>? keyConverter, DynamicConverter<V>? valueConverter}) Map<K, V>?
Converts to Map without throwing, returning null on failure.
tryToNum() num?
Converts to num without throwing, mirroring Convert.tryToNum.
tryToSet<T>({DynamicConverter<T>? elementConverter}) Set<T>?
Converts to Set without throwing, returning null on 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 converter before any lookup.
withDefault(Object? value) Converter
Returns a new Converter that uses value whenever a conversion fails.

Operators

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