Compare commits
2 commits
045d0694e7
...
3f12b14e8a
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3f12b14e8a | ||
![]() |
a45378a094 |
4 changed files with 59 additions and 31 deletions
|
@ -28,3 +28,17 @@ class MainApp extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
SnackBar buildErrorSnackBar(BuildContext context, String error) {
|
||||
return SnackBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
content: Row(
|
||||
spacing: 10,
|
||||
children: [
|
||||
Icon(Icons.error, color: Colors.red,),
|
||||
Text(error, style: TextStyle(color: Theme.of(context).colorScheme.onSecondaryContainer),),
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:dartssh2/dartssh2.dart';
|
|||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:file_selector/file_selector.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluxcloud/main.dart';
|
||||
import 'package:fluxcloud/sftp_worker.dart';
|
||||
|
||||
import 'widgets/operation_buttons.dart';
|
||||
|
@ -39,7 +40,7 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
|||
}
|
||||
catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, e.toString()));
|
||||
ScaffoldMessenger.of(context).showSnackBar(buildErrorSnackBar(context, e.toString()));
|
||||
}
|
||||
}
|
||||
setState(() => _isLoading = false);
|
||||
|
@ -168,7 +169,7 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
|||
}
|
||||
catch (e) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, e.toString()));
|
||||
ScaffoldMessenger.of(context).showSnackBar(buildErrorSnackBar(context, e.toString()));
|
||||
}
|
||||
}
|
||||
if (context.mounted) {
|
||||
|
@ -202,7 +203,7 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
|||
}
|
||||
catch (e) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, e.toString()));
|
||||
ScaffoldMessenger.of(context).showSnackBar(buildErrorSnackBar(context, e.toString()));
|
||||
}
|
||||
}
|
||||
setState(() => _progress = null);
|
||||
|
@ -214,17 +215,4 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
|||
);
|
||||
}
|
||||
|
||||
SnackBar _buildErrorSnackBar(BuildContext context, String error) {
|
||||
return SnackBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
content: Row(
|
||||
spacing: 10,
|
||||
children: [
|
||||
Icon(Icons.error, color: Colors.red,),
|
||||
Text(error, style: TextStyle(color: Theme.of(context).colorScheme.onSecondaryContainer),),
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,13 @@ class Remove extends SftpCommand {
|
|||
Remove(this.dirEntry, this.path);
|
||||
}
|
||||
|
||||
class Rename extends SftpCommand {
|
||||
final String oldpath;
|
||||
final String newpath;
|
||||
|
||||
Rename(this.oldpath, this.newpath);
|
||||
}
|
||||
|
||||
|
||||
class SftpWorker {
|
||||
|
||||
|
@ -166,6 +173,14 @@ class SftpWorker {
|
|||
on SftpStatusError catch (e) {
|
||||
sendPort.send((id, RemoteError(e.message, '')));
|
||||
}
|
||||
case Rename(:final oldpath, :final newpath):
|
||||
try {
|
||||
await sftpClient.rename(oldpath, newpath);
|
||||
sendPort.send((id, 0));
|
||||
}
|
||||
on SftpStatusError catch (e) {
|
||||
sendPort.send((id, RemoteError(e.message, '')));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -232,4 +247,12 @@ class SftpWorker {
|
|||
await completer.future;
|
||||
}
|
||||
|
||||
Future<void> rename(String oldpath, String newpath) async {
|
||||
final completer = Completer.sync();
|
||||
final id = _idCounter++;
|
||||
_activeRequests[id] = completer;
|
||||
_commands.send((id, Rename(oldpath, newpath)));
|
||||
await completer.future;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluxcloud/main.dart';
|
||||
import 'package:fluxcloud/sftp_worker.dart';
|
||||
|
||||
class OperationButtons extends StatelessWidget {
|
||||
|
@ -50,19 +51,19 @@ class OperationButtons extends StatelessWidget {
|
|||
TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancel')),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
// try {
|
||||
// await sftpWorker.rename('${path}${dirEntry.filename}', '${widget.path}${newNameController.text}');
|
||||
// _listDir();
|
||||
// }
|
||||
// on SftpStatusError catch (e) {
|
||||
// if (context.mounted) {
|
||||
// ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, e.message));
|
||||
// }
|
||||
// }
|
||||
// if (context.mounted) {
|
||||
// Navigator.pop(context);
|
||||
// }
|
||||
//
|
||||
try {
|
||||
await sftpWorker.rename('$path${dirEntry.filename}', '$path${newNameController.text}');
|
||||
listDir();
|
||||
}
|
||||
on SftpStatusError catch (e) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(buildErrorSnackBar(context, e.message));
|
||||
}
|
||||
}
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
},
|
||||
child: Text('Rename')
|
||||
),
|
||||
|
@ -97,7 +98,9 @@ class OperationButtons extends StatelessWidget {
|
|||
await sftpWorker.remove(dirEntry, path);
|
||||
}
|
||||
catch (e) {
|
||||
print(e.toString());
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(buildErrorSnackBar(context, e.toString()));
|
||||
}
|
||||
}
|
||||
listDir();
|
||||
if (context.mounted) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue