#33 new: upload file in sftp

This commit is contained in:
lollipopkit
2023-06-01 16:07:09 +08:00
parent 026e951604
commit f0bf95a7d2
6 changed files with 66 additions and 7 deletions

View File

@@ -56,6 +56,9 @@ class MyApp extends StatelessWidget {
appBarTheme: const AppBarTheme( appBarTheme: const AppBarTheme(
backgroundColor: Colors.black, backgroundColor: Colors.black,
), ),
dialogTheme: const DialogTheme(
backgroundColor: Colors.black,
),
bottomSheetTheme: const BottomSheetThemeData( bottomSheetTheme: const BottomSheetThemeData(
backgroundColor: Colors.black, backgroundColor: Colors.black,
), ),
@@ -68,6 +71,9 @@ class MyApp extends StatelessWidget {
navigationBarTheme: const NavigationBarThemeData( navigationBarTheme: const NavigationBarThemeData(
backgroundColor: Colors.black, backgroundColor: Colors.black,
), ),
popupMenuTheme: const PopupMenuThemeData(
color: Colors.black,
),
), ),
home: const HomePage(), home: const HomePage(),
); );

View File

@@ -73,3 +73,7 @@ String getTime(int? unixMill) {
.toString() .toString()
.replaceFirst('.000', ''); .replaceFirst('.000', '');
} }
String pathJoin(String path1, String path2) {
return path1 + (path1.endsWith('/') ? '' : '/') + path2;
}

View File

@@ -1,3 +1,5 @@
import 'package:toolbox/core/utils/misc.dart';
class PathWithPrefix { class PathWithPrefix {
final String _prefixPath; final String _prefixPath;
String _path = '/'; String _path = '/';
@@ -19,7 +21,7 @@ class PathWithPrefix {
_path = '/'; _path = '/';
return; return;
} }
_path = _path + (_path.endsWith('/') ? '' : '/') + newPath; _path = pathJoin(_path, newPath);
} }
bool undo() { bool undo() {

View File

@@ -1,3 +1,5 @@
import 'package:toolbox/core/utils/misc.dart';
class AbsolutePath { class AbsolutePath {
String _path; String _path;
String get path => _path; String get path => _path;
@@ -22,7 +24,7 @@ class AbsolutePath {
_path = newPath; _path = newPath;
return; return;
} }
_path = _path + (_path.endsWith('/') ? '' : '/') + newPath; _path = pathJoin(_path, newPath);
} }
bool undo() { bool undo() {

View File

@@ -24,7 +24,9 @@ import '../../widget/fade_in.dart';
import 'downloading.dart'; import 'downloading.dart';
class SFTPDownloadedPage extends StatefulWidget { 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 @override
State<SFTPDownloadedPage> createState() => _SFTPDownloadedPageState(); State<SFTPDownloadedPage> createState() => _SFTPDownloadedPageState();
@@ -128,9 +130,9 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
.substring(0, stat.modified.toString().length - 4), .substring(0, stat.modified.toString().length - 4),
style: grey, style: grey,
), ),
onTap: () { onTap: () async {
if (!isDir) { if (!isDir) {
showFileActionDialog(file); await showFileActionDialog(file);
return; return;
} }
_path!.update(fileName); _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; 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( showRoundDialog(
context: context, context: context,
child: Column( child: Column(

View File

@@ -8,6 +8,7 @@ import 'package:toolbox/core/extension/navigator.dart';
import 'package:toolbox/core/extension/sftpfile.dart'; import 'package:toolbox/core/extension/sftpfile.dart';
import 'package:toolbox/data/res/misc.dart'; import 'package:toolbox/data/res/misc.dart';
import 'package:toolbox/view/page/editor.dart'; import 'package:toolbox/view/page/editor.dart';
import 'package:toolbox/view/page/sftp/downloaded.dart';
import '../../../core/extension/numx.dart'; import '../../../core/extension/numx.dart';
import '../../../core/extension/stringx.dart'; import '../../../core/extension/stringx.dart';
@@ -104,6 +105,7 @@ class _SFTPPageState extends State<SFTPPage> {
), ),
_buildAddBtn(), _buildAddBtn(),
_buildGotoBtn(), _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() { Widget _buildAddBtn() {
return IconButton( return IconButton(
onPressed: (() => showRoundDialog( onPressed: (() => showRoundDialog(
@@ -534,7 +561,7 @@ class _SFTPPageState extends State<SFTPPage> {
String _getRemotePath(SftpName name) { String _getRemotePath(SftpName name) {
final prePath = _status.path!.path; final prePath = _status.path!.path;
return prePath + (prePath.endsWith('/') ? '' : '/') + name.filename; return pathJoin(prePath, name.filename);
} }
Future<void> _listDir({String? path, SSHClient? client}) async { Future<void> _listDir({String? path, SSHClient? client}) async {