move working
This commit is contained in:
parent
7ea9e98789
commit
a66ed70532
4 changed files with 107 additions and 2 deletions
|
@ -1,10 +1,12 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:dartssh2/dartssh2.dart';
|
||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:file_selector/file_selector.dart';
|
import 'package:file_selector/file_selector.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:fluxcloud/main.dart';
|
import 'package:fluxcloud/main.dart';
|
||||||
import 'package:fluxcloud/sftp_provider.dart';
|
import 'package:fluxcloud/sftp_provider.dart';
|
||||||
|
import 'package:path/path.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import 'widgets/operation_buttons.dart';
|
import 'widgets/operation_buttons.dart';
|
||||||
|
@ -74,6 +76,7 @@ class SftpExplorer extends StatelessWidget {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
floatingActionButton: _buildFABs(context),
|
floatingActionButton: _buildFABs(context),
|
||||||
|
bottomNavigationBar: _buildCopyMoveButton(context),
|
||||||
body: PopScope(
|
body: PopScope(
|
||||||
canPop: false,
|
canPop: false,
|
||||||
onPopInvokedWithResult: (_, _) {
|
onPopInvokedWithResult: (_, _) {
|
||||||
|
@ -203,4 +206,68 @@ class SftpExplorer extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildCopyMoveButton(BuildContext context) {
|
||||||
|
return Selector<SftpProvider, (List<String>?, bool)>(
|
||||||
|
selector: (_, sftpProvider) => (sftpProvider.toBeMovedOrCopied, sftpProvider.isCopy),
|
||||||
|
builder: (_, data, __) {
|
||||||
|
final (toBeMovedOrCopied, isCopy) = data;
|
||||||
|
if (toBeMovedOrCopied == null) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
child: Row(
|
||||||
|
spacing: 10,
|
||||||
|
children: [
|
||||||
|
Expanded(child: ElevatedButton(
|
||||||
|
onPressed: () async {
|
||||||
|
final sftpProvider = context.read<SftpProvider>();
|
||||||
|
for (final filePath in toBeMovedOrCopied) {
|
||||||
|
try {
|
||||||
|
if (isCopy) {
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
final fileName = basename(filePath);
|
||||||
|
await sftpProvider.sftpWorker.rename(filePath, '${sftpProvider.path}$fileName');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
if (context.mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(buildErrorSnackBar(context, e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sftpProvider.setCopyOrMoveFiles(null, isCopy);
|
||||||
|
sftpProvider.listDir();
|
||||||
|
},
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
||||||
|
foregroundColor: Theme.of(context).colorScheme.onSecondaryContainer
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Text(isCopy ? 'Copy Here' : 'Move Here'),
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
context.read<SftpProvider>().setCopyOrMoveFiles(null, isCopy);
|
||||||
|
},
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
||||||
|
foregroundColor: Theme.of(context).colorScheme.onSecondaryContainer
|
||||||
|
),
|
||||||
|
icon: Padding(
|
||||||
|
padding: const EdgeInsets.all(4),
|
||||||
|
child: Icon(Icons.close),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,9 @@ class SftpProvider extends ChangeNotifier {
|
||||||
double? _uploadProgress;
|
double? _uploadProgress;
|
||||||
double? _downloadProgress;
|
double? _downloadProgress;
|
||||||
|
|
||||||
|
List<String>? _toBeMovedOrCopied;
|
||||||
|
bool _isCopy = false;
|
||||||
|
|
||||||
SftpProvider(this._sftpWorker) {
|
SftpProvider(this._sftpWorker) {
|
||||||
listDir();
|
listDir();
|
||||||
}
|
}
|
||||||
|
@ -25,6 +28,9 @@ class SftpProvider extends ChangeNotifier {
|
||||||
double? get uploadProgress => _uploadProgress;
|
double? get uploadProgress => _uploadProgress;
|
||||||
double? get downloadProgress => _downloadProgress;
|
double? get downloadProgress => _downloadProgress;
|
||||||
|
|
||||||
|
List<String>? get toBeMovedOrCopied => _toBeMovedOrCopied;
|
||||||
|
bool get isCopy => _isCopy;
|
||||||
|
|
||||||
Future<void> listDir() async {
|
Future<void> listDir() async {
|
||||||
_isLoading = true;
|
_isLoading = true;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -54,4 +60,10 @@ class SftpProvider extends ChangeNotifier {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setCopyOrMoveFiles(List<String>? files, bool isCopy) {
|
||||||
|
_toBeMovedOrCopied = files;
|
||||||
|
_isCopy = isCopy;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,13 @@ class DownloadFile extends SftpCommand {
|
||||||
DownloadFile(this.file, this.path, this.downloadPath);
|
DownloadFile(this.file, this.path, this.downloadPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Copy extends SftpCommand {
|
||||||
|
final String filePath;
|
||||||
|
final String copyToPath;
|
||||||
|
|
||||||
|
Copy(this.filePath, this.copyToPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class SftpWorker {
|
class SftpWorker {
|
||||||
|
|
||||||
|
@ -227,6 +234,15 @@ class SftpWorker {
|
||||||
}
|
}
|
||||||
case DownloadFile():
|
case DownloadFile():
|
||||||
downloadController.add((id, command));
|
downloadController.add((id, command));
|
||||||
|
case Copy(:final filePath, :final copyToPath):
|
||||||
|
try {
|
||||||
|
// TODO: complete this
|
||||||
|
sendPort.send((id, 0));
|
||||||
|
}
|
||||||
|
on SftpStatusError catch (e) {
|
||||||
|
sendPort.send((id, RemoteError(e.message, '')));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -309,4 +325,12 @@ class SftpWorker {
|
||||||
return controller.stream;
|
return controller.stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> copy(String filePath, String copyToPath) async {
|
||||||
|
final completer = Completer.sync();
|
||||||
|
final id = _idCounter++;
|
||||||
|
_activeRequests[id] = completer;
|
||||||
|
_commands.send((id, Copy(filePath, copyToPath)));
|
||||||
|
await completer.future;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,13 +20,15 @@ class OperationButtons extends StatelessWidget {
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
final filePaths = dirEntries.map((dirEntry) => '${sftpProvider.path}${dirEntry.filename}').toList();
|
||||||
|
sftpProvider.setCopyOrMoveFiles(filePaths, false);
|
||||||
},
|
},
|
||||||
icon: Icon(Icons.drive_file_move)
|
icon: Icon(Icons.drive_file_move)
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
final filePaths = dirEntries.map((dirEntry) => '${sftpProvider.path}${dirEntry.filename}').toList();
|
||||||
|
sftpProvider.setCopyOrMoveFiles(filePaths, true);
|
||||||
},
|
},
|
||||||
icon: Icon(Icons.copy)
|
icon: Icon(Icons.copy)
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue