retrieveModelFromListJson method

Future<List<ModelEntity>> retrieveModelFromListJson(
  1. List json,
  2. Map<String, ModelEntity> models
)

Implementation

Future<List<ModelEntity>> retrieveModelFromListJson(
    List<dynamic> json, Map<String, ModelEntity> models) async {
  if (json.isEmpty) {
    return [];
  }

  // Creare una lista di Future per ogni elemento JSON
  var futures = <Future<ModelEntity>>[];
  for (var element in json) {
    futures.add(retrieveModelFromJson(element, models));
  }

  try {
    // Attendi il completamento di tutte le Future
    final results = await Future.wait(futures, eagerError: false);
    return results.whereType<ModelEntity>().toList();
  } catch (e) {
    Logger.printError('retrieveModelFromListJson: $e');
    return []; // Gestisci l'errore come preferisci
  }
}