Files
flutter_server_box/lib/data/model/sftp/download_status.dart
Junyuan Feng b824e06736 New feat
- SFTP download
- open downloaded files in other apps
2022-05-07 22:15:09 +08:00

56 lines
1.3 KiB
Dart

import 'package:toolbox/data/model/sftp/download_worker.dart';
class SftpDownloadStatus {
final int id;
final DownloadItem item;
final void Function() notifyListeners;
late SftpDownloadWorker worker;
String get fileName => item.localPath.split('/').last;
// status of the download
double? progress;
SftpWorkerStatus? status;
int? size;
Exception? error;
Duration? spentTime;
SftpDownloadStatus(this.item, this.notifyListeners, {String? key})
: id = DateTime.now().microsecondsSinceEpoch {
worker =
SftpDownloadWorker(onNotify: onNotify, item: item, privateKey: key);
worker.init();
}
@override
bool operator ==(Object other) =>
other is SftpDownloadStatus && id == other.id;
@override
int get hashCode => id ^ super.hashCode;
void onNotify(dynamic event) {
switch (event.runtimeType) {
case SftpWorkerStatus:
status = event;
break;
case double:
progress = event;
break;
case int:
size = event;
break;
case Exception:
error = event;
break;
case Duration:
spentTime = event;
break;
default:
}
notifyListeners();
}
}
enum SftpWorkerStatus { preparing, sshConnectted, downloading, finished }