This commit is contained in:
RafayAhmad7548 2025-07-28 09:20:08 +05:00
parent 3d86afa592
commit 1e0457ecd1

View file

@ -65,7 +65,44 @@ class _SftpExplorerState extends State<SftpExplorer> {
icon: Icon(Icons.copy) icon: Icon(Icons.copy)
), ),
IconButton( IconButton(
onPressed: () {}, onPressed: () {
final newNameController = TextEditingController(text: dirEntry.filename);
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Rename'),
content: TextField(
controller: newNameController,
autofocus: true,
decoration: InputDecoration(
labelText: 'Enter new name'
),
),
actions: [
TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancel')),
TextButton(
onPressed: () async {
try {
await widget.sftpClient.rename('${widget.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')
),
],
)
);
},
icon: Icon(Icons.drive_file_rename_outline) icon: Icon(Icons.drive_file_rename_outline)
), ),
IconButton( IconButton(
@ -182,9 +219,10 @@ class _SftpExplorerState extends State<SftpExplorer> {
FloatingActionButton( FloatingActionButton(
heroTag: 'upload-file', heroTag: 'upload-file',
onPressed: () async { onPressed: () async {
// TODO: upload hangingig on android
final List<XFile> files = await openFiles(); final List<XFile> files = await openFiles();
for (XFile file in files) { try {
try { for (XFile file in files) {
final remoteFile = await widget.sftpClient.open('${widget.path}${file.name}', mode: SftpFileOpenMode.create | SftpFileOpenMode.write | SftpFileOpenMode.exclusive); final remoteFile = await widget.sftpClient.open('${widget.path}${file.name}', mode: SftpFileOpenMode.create | SftpFileOpenMode.write | SftpFileOpenMode.exclusive);
final fileSize = await file.length(); final fileSize = await file.length();
final uploader = remoteFile.write( final uploader = remoteFile.write(
@ -196,17 +234,17 @@ class _SftpExplorerState extends State<SftpExplorer> {
_loadingFileName = file.name; _loadingFileName = file.name;
}); });
await uploader.done; await uploader.done;
setState(() => _loader = null);
_listDir();
} }
on SftpStatusError catch (e) { setState(() => _loader = null);
if (context.mounted) { _listDir();
if (e.code == 4) { }
ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, 'File Already Exists')); on SftpStatusError catch (e) {
} if (context.mounted) {
else { if (e.code == 4) {
ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, 'Error: ${e.message}')); ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, 'File Already Exists'));
} }
else {
ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, 'Error: ${e.message}'));
} }
} }
} }