deleteModel static method

Future<List<AIModel>> deleteModel(
  1. AIModel aiModel
)

Implementation

static Future<List<AIModel>> deleteModel(AIModel aiModel) async {
  List<AIModel> models = await loadAllModels();

  // remove the model
  models.removeWhere((model) => model.id == aiModel.id);
  await ManagerAIDatabase.deleteMap(aiModel.id);

  // check if no model is default and set the first model as default
  if (models.any((model) => model.defaultModel == true) == false &&
      models.isNotEmpty) {
    models[0].defaultModel = true;
  }

  // save the models
  return await saveModels(models);
}