opt.: cancel sftp mission

This commit is contained in:
lollipopkit
2023-07-29 18:24:22 +08:00
parent e13c5910ec
commit 0f83d10bfa
12 changed files with 277 additions and 230 deletions

View File

@@ -8,21 +8,8 @@ class SftpProvider extends ProviderBase {
final List<SftpReqStatus> _status = [];
List<SftpReqStatus> get status => _status;
Iterable<SftpReqStatus> gets({int? id, String? fileName}) {
Iterable<SftpReqStatus> found = [];
if (id != null) {
found = _status.where((e) => e.id == id);
}
if (fileName != null) {
found = found.where((e) => e.req.localPath.split('/').last == fileName);
}
return found;
}
SftpReqStatus? get({int? id, String? name}) {
final found = gets(id: id, fileName: name);
if (found.isEmpty) return null;
return found.first;
SftpReqStatus? get(int id) {
return _status.singleWhere((element) => element.id == id);
}
void add(SftpReq req, {Completer? completer}) {
@@ -32,4 +19,19 @@ class SftpProvider extends ProviderBase {
req: req,
));
}
@override
void dispose() {
for (final item in _status) {
item.worker.dispose();
}
super.dispose();
}
void cancel(int id) {
final idx = _status.indexWhere((element) => element.id == id);
_status[idx].worker.dispose();
_status.removeAt(idx);
notifyListeners();
}
}