getModels method

Future<List<T>> getModels()

Implementation

Future<List<T>> getModels() async {
  if (_all.isNotEmpty) {
    return await onSort(_all.values.toList());
  }

  /**
   * Load models from database.
   */
  List<Map<String, dynamic>>? modelDatas = await Database.getModels(getId());

  if (modelDatas == null) {
    return [];
  }

  List<dynamic> result = modelDatas.map((modelData) {
    return Model.get(Model.typeToId(T))(modelData);
  }).toList();

  return result.cast<T>();
}