createInstanceWithBestConstructor method
O?
createInstanceWithBestConstructor(
- Map<
String, Object?> map, { - FieldNameResolver? fieldNameResolver,
- FieldValueResolver? fieldValueResolver,
- bool? allowEmptyConstructors,
- bool? allowOptionalOnlyConstructors,
Creates an instance with the constructor returned by getBestConstructorForMap,
using map
entries as parameters.
- Throws UnresolvedParameterError when it's its impossible to call any constructor due to unresolved parameters.
- Throws any error thrown by a constructor invocation.
Implementation
O? createInstanceWithBestConstructor(
Map<String, Object?> map, {
FieldNameResolver? fieldNameResolver,
FieldValueResolver? fieldValueResolver,
bool? allowEmptyConstructors,
bool? allowOptionalOnlyConstructors,
}) {
allowOptionalOnlyConstructors ??= map.isEmpty;
allowEmptyConstructors ??= map.isEmpty;
var constructors = getBestConstructorsForMap(map,
fieldNameResolver: fieldNameResolver,
fieldValueResolver: fieldValueResolver,
allowEmptyConstructors: allowEmptyConstructors,
allowOptionalOnlyConstructors: allowOptionalOnlyConstructors);
return createInstanceWithConstructors(constructors, map,
fieldNameResolver: fieldNameResolver,
fieldValueResolver: fieldValueResolver);
}