make copy work, also some abstraction and new provider

This commit is contained in:
RafayAhmad7548 2025-08-16 10:12:51 +05:00
parent a66ed70532
commit 869f2c14c3
6 changed files with 145 additions and 107 deletions

View file

@ -0,0 +1,40 @@
import 'package:flutter/material.dart';
class SftpLoadingProvider extends ChangeNotifier {
double? _uploadProgress;
double? _downloadProgress;
double? _copyProgress;
List<String>? _toBeMovedOrCopied;
bool _isCopy = false;
double? get copyProgress => _copyProgress;
double? get uploadProgress => _uploadProgress;
double? get downloadProgress => _downloadProgress;
List<String>? get toBeMovedOrCopied => _toBeMovedOrCopied;
bool get isCopy => _isCopy;
void setUploadProgress(double? progress) {
_uploadProgress = progress;
notifyListeners();
}
void setDownloadProgress(double? progress) {
_downloadProgress = progress;
notifyListeners();
}
void setCopyProgress(double? progress) {
_copyProgress = progress;
notifyListeners();
}
void setCopyOrMoveFiles(List<String>? files, bool isCopy) {
_toBeMovedOrCopied = files;
_isCopy = isCopy;
notifyListeners();
}
}

View file

@ -0,0 +1,41 @@
import 'package:dartssh2/dartssh2.dart';
import 'package:flutter/material.dart';
import 'package:fluxcloud/sftp_worker.dart';
class SftpProvider extends ChangeNotifier {
final SftpWorker _sftpWorker;
String _path = '/';
bool _isLoading = false;
late List<SftpName> _dirContents;
SftpProvider(this._sftpWorker) {
listDir();
}
SftpWorker get sftpWorker => _sftpWorker;
String get path => _path;
bool get isLoading => _isLoading;
List<SftpName> get dirContents => _dirContents;
Future<void> listDir() async {
_isLoading = true;
notifyListeners();
_dirContents = await _sftpWorker.listdir(_path);
_isLoading = false;
notifyListeners();
}
void goToPrevDir() {
_path = _path.substring(0, _path.length - 1);
_path = _path.substring(0, _path.lastIndexOf('/')+1);
listDir();
}
void goToDir(String path) {
_path = path;
listDir();
}
}