diff --git a/lib/view/page/sftp/view.dart b/lib/view/page/sftp/view.dart index 216f8e7e..b317a8e8 100644 --- a/lib/view/page/sftp/view.dart +++ b/lib/view/page/sftp/view.dart @@ -18,6 +18,7 @@ import '../../../data/provider/sftp_download.dart'; import '../../../data/res/path.dart'; import '../../../data/store/private_key.dart'; import '../../../locator.dart'; +import '../../widget/center_loading.dart'; import '../../widget/fade_in.dart'; import '../../widget/two_line_text.dart'; import 'downloading.dart'; @@ -299,9 +300,7 @@ class _SFTPPageState extends State { TextButton( onPressed: () async { Navigator.of(context).pop(); - final prePath = _status.path!.path; - final remotePath = - prePath + (prePath.endsWith('/') ? '' : '/') + name.filename; + final remotePath = _getRemotePath(name); final local = '${(await sftpDir).path}$remotePath'; final pubKeyId = widget.spi.pubKeyId; @@ -330,7 +329,8 @@ class _SFTPPageState extends State { showRoundDialog( context, _s.attention, - Text('${_s.sureDelete(file.filename)}\n${isDir ? _s.sureDirEmpty : ''}'), + Text( + '${_s.sureDelete(file.filename)}${isDir ? '\n${_s.sureDirEmpty}' : ''}'), [ TextButton( onPressed: () => Navigator.of(context).pop(), @@ -338,12 +338,32 @@ class _SFTPPageState extends State { ), TextButton( onPressed: () async { - if (file.attr.isDirectory) { - await _status.client!.rmdir(file.filename); - } else { - await _status.client!.remove(file.filename); - } Navigator.of(context).pop(); + showRoundDialog(context, 'Waiting...', centerSizedLoading, [], + barrierDismiss: false); + final remotePath = _getRemotePath(file); + try { + if (file.attr.isDirectory) { + await _status.client!.rmdir(remotePath); + } else { + await _status.client!.remove(remotePath); + } + Navigator.of(context).pop(); + } catch (e) { + Navigator.of(context).pop(); + showRoundDialog( + context, + _s.attention, + Text(e.toString()), + [ + TextButton( + onPressed: () => Navigator.of(context).pop(), + child: Text(_s.ok), + ) + ], + ); + return; + } listDir(); }, child: Text( @@ -495,6 +515,11 @@ class _SFTPPageState extends State { ); } + String _getRemotePath(SftpName name) { + final prePath = _status.path!.path; + return prePath + (prePath.endsWith('/') ? '' : '/') + name.filename; + } + Future listDir({String? path, SSHClient? client}) async { if (_status.isBusy) { return;