Files
flutter_server_box/lib/data/provider/sftp_download.dart
lollipopkit be1a162632 fix & opt.
2023-01-28 15:35:19 +08:00

33 lines
933 B
Dart

import 'package:toolbox/core/provider_base.dart';
import '../model/sftp/download_item.dart';
import '../model/sftp/download_status.dart';
class SftpDownloadProvider extends ProviderBase {
final List<SftpDownloadStatus> _status = [];
List<SftpDownloadStatus> get status => _status;
List<SftpDownloadStatus> gets({int? id, String? fileName}) {
var found = <SftpDownloadStatus>[];
if (id != null) {
found = _status.where((e) => e.id == id).toList();
}
if (fileName != null) {
found = found
.where((e) => e.item.localPath.split('/').last == fileName)
.toList();
}
return found;
}
SftpDownloadStatus? get({int? id, String? name}) {
final found = gets(id: id, fileName: name);
if (found.isEmpty) return null;
return found.first;
}
void add(DownloadItem item, {String? key}) {
_status.add(SftpDownloadStatus(item, notifyListeners, key: key));
}
}