setConversionService method

  1. @override
void setConversionService(
  1. ConversionService conversionService
)
override

Sets an assigned ConversionService.

The conversion service handles type conversion operations throughout the framework, particularly for configuration properties, data binding, and format parsing.

Built-in Conversions:

  • String to primitive types (int, double, bool, DateTime, etc.)
  • Collection and array conversions
  • Custom object marshalling/unmarshalling
  • Format-aware parsing (dates, numbers, currencies)

Example:

// Use default conversion service
context.setConversionService(DefaultConversionService());

// Or custom implementation
final customService = MyConversionService();
customService.addConverter(String, Money.class, MoneyConverter());
context.setConversionService(customService);

// Usage in application
final service = context.getConversionService();
final result = service.convert<String, double>("3.14");
print("Parsed double: $result"); // Parsed double: 3.14

// Custom type conversion
final money = service.convert<String, Money>("\$123.45");
print("Parsed money: ${money.amount}"); // Parsed money: 123.45

Implementation

@override
void setConversionService(ConversionService conversionService) {
  _conversionService = conversionService;
}