mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
#33 new: upload file in sftp
This commit is contained in:
@@ -56,6 +56,9 @@ class MyApp extends StatelessWidget {
|
||||
appBarTheme: const AppBarTheme(
|
||||
backgroundColor: Colors.black,
|
||||
),
|
||||
dialogTheme: const DialogTheme(
|
||||
backgroundColor: Colors.black,
|
||||
),
|
||||
bottomSheetTheme: const BottomSheetThemeData(
|
||||
backgroundColor: Colors.black,
|
||||
),
|
||||
@@ -68,6 +71,9 @@ class MyApp extends StatelessWidget {
|
||||
navigationBarTheme: const NavigationBarThemeData(
|
||||
backgroundColor: Colors.black,
|
||||
),
|
||||
popupMenuTheme: const PopupMenuThemeData(
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
home: const HomePage(),
|
||||
);
|
||||
|
||||
@@ -73,3 +73,7 @@ String getTime(int? unixMill) {
|
||||
.toString()
|
||||
.replaceFirst('.000', '');
|
||||
}
|
||||
|
||||
String pathJoin(String path1, String path2) {
|
||||
return path1 + (path1.endsWith('/') ? '' : '/') + path2;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:toolbox/core/utils/misc.dart';
|
||||
|
||||
class PathWithPrefix {
|
||||
final String _prefixPath;
|
||||
String _path = '/';
|
||||
@@ -19,7 +21,7 @@ class PathWithPrefix {
|
||||
_path = '/';
|
||||
return;
|
||||
}
|
||||
_path = _path + (_path.endsWith('/') ? '' : '/') + newPath;
|
||||
_path = pathJoin(_path, newPath);
|
||||
}
|
||||
|
||||
bool undo() {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:toolbox/core/utils/misc.dart';
|
||||
|
||||
class AbsolutePath {
|
||||
String _path;
|
||||
String get path => _path;
|
||||
@@ -22,7 +24,7 @@ class AbsolutePath {
|
||||
_path = newPath;
|
||||
return;
|
||||
}
|
||||
_path = _path + (_path.endsWith('/') ? '' : '/') + newPath;
|
||||
_path = pathJoin(_path, newPath);
|
||||
}
|
||||
|
||||
bool undo() {
|
||||
|
||||
@@ -24,7 +24,9 @@ import '../../widget/fade_in.dart';
|
||||
import 'downloading.dart';
|
||||
|
||||
class SFTPDownloadedPage extends StatefulWidget {
|
||||
const SFTPDownloadedPage({Key? key}) : super(key: key);
|
||||
final bool isPickFile;
|
||||
const SFTPDownloadedPage({Key? key, this.isPickFile = false})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
State<SFTPDownloadedPage> createState() => _SFTPDownloadedPageState();
|
||||
@@ -128,9 +130,9 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
|
||||
.substring(0, stat.modified.toString().length - 4),
|
||||
style: grey,
|
||||
),
|
||||
onTap: () {
|
||||
onTap: () async {
|
||||
if (!isDir) {
|
||||
showFileActionDialog(file);
|
||||
await showFileActionDialog(file);
|
||||
return;
|
||||
}
|
||||
_path!.update(fileName);
|
||||
@@ -141,8 +143,24 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
|
||||
);
|
||||
}
|
||||
|
||||
void showFileActionDialog(FileSystemEntity file) {
|
||||
Future<void> showFileActionDialog(FileSystemEntity file) async {
|
||||
final fileName = file.path.split('/').last;
|
||||
if (widget.isPickFile) {
|
||||
await showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.pickFile),
|
||||
child: Text(fileName),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
context.pop(file.path);
|
||||
},
|
||||
child: Text(_s.ok),
|
||||
),
|
||||
]);
|
||||
return;
|
||||
}
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
child: Column(
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:toolbox/core/extension/navigator.dart';
|
||||
import 'package:toolbox/core/extension/sftpfile.dart';
|
||||
import 'package:toolbox/data/res/misc.dart';
|
||||
import 'package:toolbox/view/page/editor.dart';
|
||||
import 'package:toolbox/view/page/sftp/downloaded.dart';
|
||||
|
||||
import '../../../core/extension/numx.dart';
|
||||
import '../../../core/extension/stringx.dart';
|
||||
@@ -104,6 +105,7 @@ class _SFTPPageState extends State<SFTPPage> {
|
||||
),
|
||||
_buildAddBtn(),
|
||||
_buildGotoBtn(),
|
||||
_buildUploadBtn(),
|
||||
],
|
||||
)
|
||||
],
|
||||
@@ -112,6 +114,31 @@ class _SFTPPageState extends State<SFTPPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildUploadBtn() {
|
||||
return IconButton(
|
||||
onPressed: () async {
|
||||
final path = await AppRoute(
|
||||
const SFTPDownloadedPage(
|
||||
isPickFile: true,
|
||||
),
|
||||
'sftp dled pick')
|
||||
.go<String>(context);
|
||||
if (path == null) {
|
||||
return;
|
||||
}
|
||||
final remotePath = _status.path?.path;
|
||||
if (remotePath == null) {
|
||||
showSnackBar(context, const Text('remote path is null'));
|
||||
return;
|
||||
}
|
||||
locator<SftpProvider>().add(
|
||||
SftpReqItem(widget.spi, remotePath, path),
|
||||
SftpReqType.upload,
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.upload_file));
|
||||
}
|
||||
|
||||
Widget _buildAddBtn() {
|
||||
return IconButton(
|
||||
onPressed: (() => showRoundDialog(
|
||||
@@ -534,7 +561,7 @@ class _SFTPPageState extends State<SFTPPage> {
|
||||
|
||||
String _getRemotePath(SftpName name) {
|
||||
final prePath = _status.path!.path;
|
||||
return prePath + (prePath.endsWith('/') ? '' : '/') + name.filename;
|
||||
return pathJoin(prePath, name.filename);
|
||||
}
|
||||
|
||||
Future<void> _listDir({String? path, SSHClient? client}) async {
|
||||
|
||||
Reference in New Issue
Block a user