Convert class abstract

Backward-compatible static facade that mirrors the original ConvertObject API.

Use this class when you need stateless conversions that still honor the current ConvertConfig.effective settings.

Shared Behavior

  • mapKey and listIndex let you select nested data before conversion.
  • defaultValue short-circuits failures for the toX methods.
  • tryToX variants never throw and return null or defaultValue.
  • Collection conversions decode JSON strings when possible and then convert elements using the same conversion rules.

For fluent, stateful conversion chains, prefer value.convert from ConvertObjectExtension.

Constructors

Convert()

Properties

hashCode int
The hash code for this object.
no setterinherited
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
toString() String
A string representation of this object.
inherited

Operators

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

Static Properties

config ConvertConfig
Returns the effective configuration for the current zone.
no setter

Static Methods

buildParsingInfo({required String method, dynamic object, dynamic mapKey, int? listIndex, String? format, String? locale, bool? autoDetectFormat, bool? useCurrentLocale, bool? utc, dynamic defaultValue, dynamic converter, Type? targetType, Map<String, dynamic>? debugInfo}) Map<String, dynamic>
Builds a diagnostic map describing a conversion attempt; mainly used by tests and error reporting.
configure(ConvertConfig config) ConvertConfig
Replaces the global configuration and returns the previous instance.
runScopedConfig<T>(ConvertConfig overrides, T body()) → T
Runs body with overrides applied on top of the current effective config.
string(dynamic object, {dynamic mapKey, int? listIndex, String? defaultValue, ElementConverter<String>? converter}) String
Converts object to String, optionally selecting mapKey or listIndex first.
toBigInt(dynamic object, {dynamic mapKey, int? listIndex, BigInt? defaultValue, ElementConverter<BigInt>? converter}) BigInt
Converts object to BigInt, accepting BigInt, num, or numeric strings.
toBool(dynamic object, {dynamic mapKey, int? listIndex, bool? defaultValue, ElementConverter<bool>? converter}) bool
Converts object to bool using BoolOptions from ConvertConfig.
toDateTime(dynamic object, {dynamic mapKey, int? listIndex, String? format, String? locale, bool autoDetectFormat = false, bool useCurrentLocale = false, bool utc = false, DateTime? defaultValue, ElementConverter<DateTime>? converter}) DateTime
Converts object to a DateTime, respecting DateOptions defaults.
toDouble(dynamic object, {dynamic mapKey, int? listIndex, String? format, String? locale, double? defaultValue, ElementConverter<double>? converter}) double
Converts object to double, supporting formatted numeric strings.
toEnum<T extends Enum>(dynamic object, {required T parser(dynamic), dynamic mapKey, int? listIndex, T? defaultValue, Map<String, dynamic>? debugInfo}) → T
Converts object to an enum using the supplied parser.
toInt(dynamic object, {dynamic mapKey, int? listIndex, String? format, String? locale, int? defaultValue, ElementConverter<int>? converter}) int
Converts object to int, applying optional locale-aware formatting.
toList<T>(dynamic object, {dynamic mapKey, int? listIndex, List<T>? defaultValue, ElementConverter<T>? elementConverter}) List<T>
Converts object to List, optionally mapping each element through elementConverter.
toMap<K, V>(dynamic object, {dynamic mapKey, int? listIndex, Map<K, V>? defaultValue, ElementConverter<K>? keyConverter, ElementConverter<V>? valueConverter}) Map<K, V>
Converts object to a strongly-typed Map, optionally transforming keys and values with keyConverter and valueConverter.
toNum(dynamic object, {dynamic mapKey, int? listIndex, String? format, String? locale, num? defaultValue, ElementConverter<num>? converter}) num
Converts object to num, honoring NumberOptions defaults.
toSet<T>(dynamic object, {dynamic mapKey, int? listIndex, Set<T>? defaultValue, ElementConverter<T>? elementConverter}) Set<T>
Converts object to Set, applying elementConverter to each entry.
toType<T>(dynamic object) → T
Converts object to the requested type T.
toUri(dynamic object, {dynamic mapKey, int? listIndex, Uri? defaultValue, ElementConverter<Uri>? converter}) Uri
Converts object to Uri, honoring UriOptions from ConvertConfig.
tryToBigInt(dynamic object, {dynamic mapKey, int? listIndex, BigInt? defaultValue, ElementConverter<BigInt>? converter}) BigInt?
Converts object to BigInt without throwing.
tryToBool(dynamic object, {dynamic mapKey, int? listIndex, bool? defaultValue, ElementConverter<bool>? converter}) bool?
Converts object to bool without throwing.
tryToDateTime(dynamic object, {dynamic mapKey, int? listIndex, String? format, String? locale, bool autoDetectFormat = false, bool useCurrentLocale = false, bool utc = false, DateTime? defaultValue, ElementConverter<DateTime>? converter}) DateTime?
Like toDateTime but never throws.
tryToDouble(dynamic object, {dynamic mapKey, int? listIndex, String? format, String? locale, double? defaultValue, ElementConverter<double>? converter}) double?
Converts object to double without throwing.
tryToEnum<T extends Enum>(dynamic object, {required T parser(dynamic), dynamic mapKey, int? listIndex, T? defaultValue, Map<String, dynamic>? debugInfo}) → T?
Converts object to an enum using parser without throwing.
tryToInt(dynamic object, {dynamic mapKey, String? format, String? locale, int? listIndex, int? defaultValue, ElementConverter<int>? converter}) int?
Converts object to int without throwing.
tryToList<T>(dynamic object, {dynamic mapKey, int? listIndex, List<T>? defaultValue, ElementConverter<T>? elementConverter}) List<T>?
Converts object to List without throwing.
tryToMap<K, V>(dynamic object, {dynamic mapKey, int? listIndex, Map<K, V>? defaultValue, ElementConverter<K>? keyConverter, ElementConverter<V>? valueConverter}) Map<K, V>?
Converts object to Map without throwing.
tryToNum(dynamic object, {dynamic mapKey, String? format, String? locale, int? listIndex, num? defaultValue, ElementConverter<num>? converter}) num?
Converts object to num without throwing.
tryToSet<T>(dynamic object, {dynamic mapKey, int? listIndex, Set<T>? defaultValue, ElementConverter<T>? elementConverter}) Set<T>?
Converts object to Set without throwing.
tryToString(dynamic object, {dynamic mapKey, int? listIndex, String? defaultValue, ElementConverter<String>? converter}) String?
Converts object to String without throwing.
tryToType<T>(dynamic object) → T?
Converts object to type T without throwing.
tryToUri(dynamic object, {dynamic mapKey, int? listIndex, Uri? defaultValue, ElementConverter<Uri>? converter}) Uri?
Converts object to Uri without throwing.
updateConfig(ConvertConfig updater(ConvertConfig current)) → void
Updates the global configuration using updater.