mkdir worky
This commit is contained in:
parent
ce6374d302
commit
ae32866d46
2 changed files with 40 additions and 20 deletions
|
@ -46,6 +46,7 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
// TODO: make appbar same for all directories
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
toolbarHeight: 75,
|
toolbarHeight: 75,
|
||||||
title: Text('Explorer'),
|
title: Text('Explorer'),
|
||||||
|
@ -220,23 +221,18 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
||||||
TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancel')),
|
TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancel')),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
// try {
|
try {
|
||||||
// await widget.sftpWorker.mkdir('${widget.path}${nameController.text}');
|
await widget.sftpWorker.mkdir('${widget.path}${nameController.text}');
|
||||||
// _listDir();
|
_listDir();
|
||||||
// }
|
}
|
||||||
// on SftpStatusError catch (e) {
|
catch (e) {
|
||||||
// if (context.mounted) {
|
if (context.mounted) {
|
||||||
// if (e.code == 4) {
|
ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, e.toString()));
|
||||||
// ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, 'Folder Already Exists'));
|
}
|
||||||
// }
|
}
|
||||||
// else {
|
if (context.mounted) {
|
||||||
// ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, 'Error: ${e.message}'));
|
Navigator.pop(context);
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if (context.mounted) {
|
|
||||||
// Navigator.pop(context);
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
child: Text('Ok')
|
child: Text('Ok')
|
||||||
),
|
),
|
||||||
|
@ -260,7 +256,6 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await for (final progress in widget.sftpWorker.uploadFiles(widget.path, filePaths)) {
|
await for (final progress in widget.sftpWorker.uploadFiles(widget.path, filePaths)) {
|
||||||
print(progress);
|
|
||||||
setState(() => _progress = progress);
|
setState(() => _progress = progress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,13 @@ import 'package:path/path.dart';
|
||||||
import 'connection.dart';
|
import 'connection.dart';
|
||||||
|
|
||||||
sealed class SftpCommand {}
|
sealed class SftpCommand {}
|
||||||
|
|
||||||
class ListDir extends SftpCommand {
|
class ListDir extends SftpCommand {
|
||||||
final String path;
|
final String path;
|
||||||
|
|
||||||
ListDir(this.path);
|
ListDir(this.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
class UploadFiles extends SftpCommand {
|
class UploadFiles extends SftpCommand {
|
||||||
final String path;
|
final String path;
|
||||||
final List<String> fileNames;
|
final List<String> fileNames;
|
||||||
|
@ -20,6 +22,13 @@ class UploadFiles extends SftpCommand {
|
||||||
UploadFiles(this.path, this.fileNames);
|
UploadFiles(this.path, this.fileNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MkDir extends SftpCommand {
|
||||||
|
final String path;
|
||||||
|
|
||||||
|
MkDir(this.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class SftpWorker {
|
class SftpWorker {
|
||||||
|
|
||||||
final ReceivePort _responses;
|
final ReceivePort _responses;
|
||||||
|
@ -79,7 +88,7 @@ class SftpWorker {
|
||||||
|
|
||||||
static void _sftpCmdHandler(SendPort sendPort, ReceivePort receivePort, SftpClient sftpClient) {
|
static void _sftpCmdHandler(SendPort sendPort, ReceivePort receivePort, SftpClient sftpClient) {
|
||||||
receivePort.listen((message) async {
|
receivePort.listen((message) async {
|
||||||
final (int id, dynamic command) = message;
|
final (int id, SftpCommand command) = message;
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case ListDir(:final path):
|
case ListDir(:final path):
|
||||||
try {
|
try {
|
||||||
|
@ -115,6 +124,14 @@ class SftpWorker {
|
||||||
}
|
}
|
||||||
sendPort.send((id, 1.0));
|
sendPort.send((id, 1.0));
|
||||||
}
|
}
|
||||||
|
case MkDir(:final path):
|
||||||
|
try {
|
||||||
|
await sftpClient.mkdir(path);
|
||||||
|
sendPort.send((id, 0));
|
||||||
|
}
|
||||||
|
on SftpStatusError catch (e) {
|
||||||
|
sendPort.send((id, RemoteError(e.message, '')));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -149,7 +166,7 @@ class SftpWorker {
|
||||||
|
|
||||||
|
|
||||||
Future<List<SftpName>> listdir(String path) async {
|
Future<List<SftpName>> listdir(String path) async {
|
||||||
final completer = Completer<Object>.sync();
|
final completer = Completer.sync();
|
||||||
final id = _idCounter++;
|
final id = _idCounter++;
|
||||||
_activeRequests[id] = completer;
|
_activeRequests[id] = completer;
|
||||||
_commands.send((id, ListDir(path)));
|
_commands.send((id, ListDir(path)));
|
||||||
|
@ -165,5 +182,13 @@ class SftpWorker {
|
||||||
return controller.stream;
|
return controller.stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> mkdir(String path) async {
|
||||||
|
final completer = Completer.sync();
|
||||||
|
final id = _idCounter++;
|
||||||
|
_activeRequests[id] = completer;
|
||||||
|
_commands.send((id, MkDir(path)));
|
||||||
|
await completer.future;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue