RepoManager: Implement deleting a repo

This is ugly as fuck. All of the settings pages need a more coherent
look and feel, and need to be organized better.

This finished the implementation of multiple repos.

Fixes #229
This commit is contained in:
Vishesh Handa
2021-02-23 09:54:39 +01:00
parent 2d2e2c3d07
commit c9fce2fa33
4 changed files with 56 additions and 3 deletions

View File

@ -88,4 +88,28 @@ class RepositoryManager with ChangeNotifier {
Log.i("Switching to repo with id: $id");
await buildActiveRepository();
}
Future<void> deleteCurrent() async {
if (repoIds.length == 1) {
throw Exception("Last Repo cannot be deleted");
}
Log.i("Deleting repo: $currentId");
var i = repoIds.indexOf(currentId);
var repoPath = _repo.repoPath;
var cachePath = _repo.cacheDir;
await Directory(repoPath).delete(recursive: true);
await Directory(cachePath).delete(recursive: true);
repoIds.removeAt(i);
i = i.clamp(0, repoIds.length - 1);
currentId = repoIds[i];
await _save();
await buildActiveRepository();
}
}