resolveEntityFromMap<E extends Object> static method
FutureOr<E?>
resolveEntityFromMap<E extends Object>({
- Object? entityMap,
- Map<
String, dynamic> ? parentMap, - String? entityField,
- E? fromMap()?,
- E? empty()?,
- Type? entityType,
- EntityRepositoryProvider? entityRepositoryProvider,
- EntityHandlerProvider? entityHandlerProvider,
- EntityProvider? entityProvider,
- EntityCache? entityCache,
- EntityResolutionRules? resolutionRules,
Implementation
static FutureOr<E?> resolveEntityFromMap<E extends Object>(
{Object? entityMap,
Map<String, dynamic>? parentMap,
String? entityField,
E? Function(Map<String, dynamic> map)? fromMap,
E? Function()? empty,
Type? entityType,
EntityRepositoryProvider? entityRepositoryProvider,
EntityHandlerProvider? entityHandlerProvider,
EntityProvider? entityProvider,
EntityCache? entityCache,
EntityResolutionRules? resolutionRules}) {
entityCache ??= JsonEntityCacheSimple();
if (entityMap == null) {
if (parentMap == null || entityField == null) {
throw ArgumentError(
'If `entityValue` is null, `parentMap` and `entityField` should be provided');
}
entityMap = parentMap[entityField];
}
FutureOr<E?> entity;
if (entityMap is Map<String, dynamic>) {
if (fromMap != null) {
entity = fromMap(entityMap);
}
if (entity == null) {
var entityRepository = _resolveEntityRepository<E>(entityField,
entityType, entityRepositoryProvider, entityHandlerProvider);
entity = entityRepository?.fromMap(entityMap,
entityProvider: entityProvider,
entityCache: entityCache,
resolutionRules: resolutionRules);
}
if (entity == null) {
entityHandlerProvider ??= EntityHandlerProvider.globalProvider;
var entityHandler =
entityHandlerProvider.getEntityHandler<E>(type: entityType);
entity = entityHandler?.createFromMap(entityMap,
entityProvider: entityProvider,
entityCache: entityCache,
resolutionRules: resolutionRules);
}
} else if (entityMap is num || entityMap is String) {
var entityRepository = _resolveEntityRepository<E>(entityField,
entityType, entityRepositoryProvider, entityHandlerProvider);
entity = entityRepository?.selectByID(entityMap,
resolutionRules: resolutionRules);
}
if (entity == null && empty != null) {
return empty();
} else {
return entity;
}
}