Compare commits
No commits in common. "3f12b14e8a4cec4ccf7bdbbb4d3aadb184a6b8f2" and "045d0694e7da58e0426e121dcacd245a41d7b695" have entirely different histories.
3f12b14e8a
...
045d0694e7
4 changed files with 31 additions and 59 deletions
|
@ -28,17 +28,3 @@ 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,7 +4,6 @@ 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';
|
||||
|
@ -40,7 +39,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);
|
||||
|
@ -169,7 +168,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) {
|
||||
|
@ -203,7 +202,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);
|
||||
|
@ -215,4 +214,17 @@ 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,13 +35,6 @@ 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 {
|
||||
|
||||
|
@ -173,14 +166,6 @@ 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, '')));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -247,12 +232,4 @@ 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,6 +1,5 @@
|
|||
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 {
|
||||
|
@ -51,19 +50,19 @@ class OperationButtons extends StatelessWidget {
|
|||
TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancel')),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
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);
|
||||
}
|
||||
|
||||
// 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);
|
||||
// }
|
||||
//
|
||||
},
|
||||
child: Text('Rename')
|
||||
),
|
||||
|
@ -98,9 +97,7 @@ class OperationButtons extends StatelessWidget {
|
|||
await sftpWorker.remove(dirEntry, path);
|
||||
}
|
||||
catch (e) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(buildErrorSnackBar(context, e.toString()));
|
||||
}
|
||||
print(e.toString());
|
||||
}
|
||||
listDir();
|
||||
if (context.mounted) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue