UsedTypeConverter.forEnumColumn constructor
UsedTypeConverter.forEnumColumn(
- DartType enumType,
- bool nullable
Implementation
factory UsedTypeConverter.forEnumColumn(DartType enumType, bool nullable) {
if (enumType is! InterfaceType) {
throw InvalidTypeForEnumConverterException('Not a class', enumType);
}
final creatingClass = enumType.element2;
if (creatingClass is! EnumElement) {
throw InvalidTypeForEnumConverterException('Not an enum', enumType);
}
final className = creatingClass.name;
final suffix =
nullable ? NullabilitySuffix.question : NullabilitySuffix.none;
return UsedTypeConverter(
expression: 'const EnumIndexConverter<$className>($className.values)',
mappedType: DriftDartType(
type: creatingClass.instantiate(
typeArguments: const [], nullabilitySuffix: NullabilitySuffix.none),
overiddenSource: creatingClass.name,
nullabilitySuffix: suffix,
),
sqlType: ColumnType.integer,
);
}