checkValueProviderAssigned method
bool
checkValueProviderAssigned(
- ClassElement factoryElement
)
Implementation
bool checkValueProviderAssigned(ClassElement factoryElement) {
final fieldElement = factoryElement.fields.firstWhereOrNull(
(element) => element.name == 'valueProvider',
);
if (fieldElement != null) {
if (fieldElement.hasInitializer) {
return true;
}
if (fieldElement.getter != null && !factoryElement.isAbstract) {
logWarning(
'You define `valueProvider` field as a getter in '
'${factoryElement.thisType.getDisplayString(withNullability: false)}. '
'That type of operation is not supported.\n'
'\n'
'Prefer to use "late ValueProvider? valueProvider = {value}" syntax.\n'
'Or use mixin with "late ValueProvider? valueProvider = {value}" implementation.\n'
'\n'
'Example - `class Factory extends _\$Factory with FakerProviderMixin`',
);
}
}
if (factoryElement.mixins.isNotEmpty) {
return factoryElement.mixins.any(
(element) => checkValueProviderAssigned(element.element),
);
}
return false;
}