deleteModel method
Deletes the loaded model from storage and uninstalls it. If model was installed using the setModelPath method, it will only be uninstalled.
Nothing happens if the model is not loaded.
Also, closes the inference if it is initialized.
Implementation
@override
Future<void> deleteModel() async {
_modelCompleter = null;
final prefs = await _prefs;
if (_userSetModelPath != null) {
await onDeleteModel();
_userSetModelPath = null;
} else if (_modelFileName case String name) {
final directory = await getApplicationDocumentsDirectory();
final file = File('${directory.path}/$name');
if (await file.exists()) {
await onDeleteModel();
await file.delete();
}
}
await prefs.remove(_prefsModelKey);
_modelFileName = null;
}