fluxcloud/lib/widgets/operation_buttons.dart

125 lines
4.2 KiB
Dart
Raw Normal View History

import 'package:dartssh2/dartssh2.dart';
import 'package:flutter/material.dart';
2025-08-10 07:10:30 +05:00
import 'package:fluxcloud/main.dart';
2025-08-10 07:08:14 +05:00
import 'package:fluxcloud/sftp_worker.dart';
class OperationButtons extends StatelessWidget {
const OperationButtons({
super.key,
2025-08-10 07:08:14 +05:00
required this.sftpWorker, required this.path, required this.dirEntries, required this.listDir,
});
2025-08-10 07:08:14 +05:00
final SftpWorker sftpWorker;
final String path;
final List<SftpName> dirEntries;
final Function listDir;
@override
Widget build(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
onPressed: () {
},
icon: Icon(Icons.drive_file_move)
),
IconButton(
onPressed: () {
},
icon: Icon(Icons.copy)
),
2025-08-10 07:08:14 +05:00
if (dirEntries.length == 1)
IconButton(
onPressed: () {
2025-08-10 07:08:14 +05:00
final dirEntry = dirEntries[0];
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 {
2025-08-10 07:08:14 +05:00
// 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')
),
],
)
);
},
icon: Icon(Icons.drive_file_rename_outline)
),
IconButton(
onPressed: () {
showDialog(
context: context,
2025-08-10 07:08:14 +05:00
builder: (context) {
String warningText = 'This action cannot be undone';
if (dirEntries.length == 1 && dirEntries[0].attr.isDirectory) {
warningText = 'The contents of this folder will be deleted as well\n$warningText';
}
else if (dirEntries.length > 1) {
warningText = 'All selected files will be deleted\n$warningText';
}
return AlertDialog(
title: Text('Delete Permanently?'),
content: Text(warningText),
actions: [
TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancel')),
TextButton(
onPressed: () async {
for (final dirEntry in dirEntries) {
try {
await sftpWorker.remove(dirEntry, path);
}
catch (e) {
2025-08-10 07:10:30 +05:00
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(buildErrorSnackBar(context, e.toString()));
}
2025-08-10 07:08:14 +05:00
}
listDir();
if (context.mounted) {
Navigator.pop(context);
}
}
},
child: Text('Yes')
),
],
);
}
);
},
icon: Icon(Icons.delete)
),
],
);
}
}