registerTypeCoercion static method
void
registerTypeCoercion({
- required Type sourceType,
- required Type targetType,
- required TypeCoercionFactory factory,
Register a type coercion from one type to another.
sourceTypeName is the runtime type name of the source (e.g., 'TextStyle').
targetTypeName is the expected type name (e.g., 'TextStyle') — but in a
different package. The key used is "sourceType->targetType" but since both
may have the same name, we use the native Type objects.
sourceType and targetType are the actual Dart Type objects.
The factory converts the source to the target type.
Idempotent: Repeated calls with the same (sourceType, targetType)
pair overwrite the previously registered factory in both
_typeCoercions and _typeCoercionsByType — safe to invoke twice
when a process re-runs the generator's registerRelaxers() block.
Implementation
static void registerTypeCoercion({
required Type sourceType,
required Type targetType,
required TypeCoercionFactory factory,
}) {
final key = '${sourceType.hashCode}->${targetType.hashCode}';
_typeCoercions[key] = factory;
// Also store by type objects for lookup
_typeCoercionsByType[_TypePair(sourceType, targetType)] = factory;
}