fix: can't quit app

This commit is contained in:
LollipopKit
2022-12-20 13:40:48 +08:00
parent cfd28c3009
commit 6bda94bd7b
17 changed files with 353 additions and 380 deletions

View File

@@ -23,8 +23,7 @@ class SFTPDownloadedPage extends StatefulWidget {
class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
PathWithPrefix? _path;
String? _prefixPath;
late S s;
late ThemeData _theme;
late S _s;
@override
void initState() {
@@ -39,15 +38,14 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
@override
void didChangeDependencies() {
super.didChangeDependencies();
s = S.of(context);
_theme = Theme.of(context);
_s = S.of(context);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(s.download),
title: Text(_s.download),
actions: [
IconButton(
icon: const Icon(Icons.downloading),
@@ -68,7 +66,7 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
floatingActionButton: FloatingActionButton(
onPressed: (() {
if (_path!.path == _prefixPath) {
showSnackBar(context, Text(s.alreadyLastDir));
showSnackBar(context, Text(_s.alreadyLastDir));
return;
}
_path!.update('..');
@@ -80,18 +78,13 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
}
Widget _buildPath() {
final color = _theme.scaffoldBackgroundColor;
return Container(
color: color,
padding: const EdgeInsets.fromLTRB(11, 7, 11, 11),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Divider(),
(_path?.path ?? s.loadingFiles).omitStartStr(
style: TextStyle(
color: color.isBrightColor ? Colors.black : Colors.white),
)
(_path?.path ?? _s.loadingFiles).omitStartStr(),
],
),
);
@@ -142,30 +135,30 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
final fileName = file.path.split('/').last;
showRoundDialog(
context,
s.choose,
_s.choose,
Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Icon(Icons.delete),
title: Text(s.delete),
title: Text(_s.delete),
onTap: () {
Navigator.of(context).pop();
showRoundDialog(
context,
s.sureDelete(fileName),
_s.sureDelete(fileName),
const SizedBox(),
[
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(s.cancel)),
child: Text(_s.cancel)),
TextButton(
onPressed: () {
file.deleteSync();
setState(() {});
Navigator.of(context).pop();
},
child: Text(s.ok),
child: Text(_s.ok),
),
],
);
@@ -173,7 +166,7 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
),
ListTile(
leading: const Icon(Icons.open_in_new),
title: Text(s.open),
title: Text(_s.open),
onTap: () {
shareFiles(context, [file.absolute.path]);
},
@@ -183,7 +176,7 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
[
TextButton(
onPressed: (() => Navigator.of(context).pop()),
child: Text(s.close))
child: Text(_s.close))
],
);
}

View File

@@ -17,12 +17,12 @@ class SFTPDownloadingPage extends StatefulWidget {
}
class _SFTPDownloadingPageState extends State<SFTPDownloadingPage> {
late S s;
late S _s;
@override
void didChangeDependencies() {
super.didChangeDependencies();
s = S.of(context);
_s = S.of(context);
}
@override
@@ -30,7 +30,7 @@ class _SFTPDownloadingPageState extends State<SFTPDownloadingPage> {
return Scaffold(
appBar: AppBar(
title: Text(
s.download,
_s.download,
style: textSize18,
),
),
@@ -42,7 +42,7 @@ class _SFTPDownloadingPageState extends State<SFTPDownloadingPage> {
return Consumer<SftpDownloadProvider>(builder: (__, pro, _) {
if (pro.status.isEmpty) {
return Center(
child: Text(s.sftpNoDownloadTask),
child: Text(_s.sftpNoDownloadTask),
);
}
return ListView.builder(
@@ -81,7 +81,7 @@ class _SFTPDownloadingPageState extends State<SFTPDownloadingPage> {
final time = status.spentTime.toString();
return _wrapInCard(
status,
'${s.downloadFinished} ${s.spentTime(time == 'null' ? s.unknown : (time.substring(0, time.length - 7)))}',
'${_s.downloadFinished} ${_s.spentTime(time == 'null' ? _s.unknown : (time.substring(0, time.length - 7)))}',
trailing: IconButton(
onPressed: () => shareFiles(context, [status.item.localPath]),
icon: const Icon(Icons.open_in_new),
@@ -90,18 +90,18 @@ class _SFTPDownloadingPageState extends State<SFTPDownloadingPage> {
case SftpWorkerStatus.downloading:
return _wrapInCard(
status,
s.downloadStatus((status.progress ?? 0.0).toStringAsFixed(2),
_s.downloadStatus((status.progress ?? 0.0).toStringAsFixed(2),
(status.size ?? 0).convertBytes),
trailing:
CircularProgressIndicator(value: (status.progress ?? 0) / 100));
case SftpWorkerStatus.preparing:
return _wrapInCard(status, s.sftpDlPrepare, trailing: loadingIcon);
return _wrapInCard(status, _s.sftpDlPrepare, trailing: loadingIcon);
case SftpWorkerStatus.sshConnectted:
return _wrapInCard(status, s.sftpSSHConnected, trailing: loadingIcon);
return _wrapInCard(status, _s.sftpSSHConnected, trailing: loadingIcon);
default:
return _wrapInCard(
status,
s.unknown,
_s.unknown,
trailing: const Icon(
Icons.error,
size: 40,

View File

@@ -35,13 +35,13 @@ class _SFTPPageState extends State<SFTPPage> {
final ScrollController _scrollController = ScrollController();
late MediaQueryData _media;
late S s;
late S _s;
@override
void didChangeDependencies() {
super.didChangeDependencies();
_media = MediaQuery.of(context);
s = S.of(context);
_s = S.of(context);
}
@override
@@ -61,24 +61,24 @@ class _SFTPPageState extends State<SFTPPage> {
IconButton(
onPressed: (() => showRoundDialog(
context,
s.choose,
_s.choose,
Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Icon(Icons.folder),
title: Text(s.createFolder),
title: Text(_s.createFolder),
onTap: () => mkdir(context)),
ListTile(
leading: const Icon(Icons.insert_drive_file),
title: Text(s.createFile),
title: Text(_s.createFile),
onTap: () => newFile(context)),
],
),
[
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(s.close))
child: Text(_s.close))
],
)),
icon: const Icon(Icons.add),
@@ -167,24 +167,24 @@ class _SFTPPageState extends State<SFTPPage> {
void onItemPress(BuildContext context, SftpName file, bool showDownload) {
showRoundDialog(
context,
s.choose,
_s.choose,
Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Icon(Icons.delete),
title: Text(s.delete),
title: Text(_s.delete),
onTap: () => delete(context, file),
),
ListTile(
leading: const Icon(Icons.edit),
title: Text(s.rename),
title: Text(_s.rename),
onTap: () => rename(context, file),
),
showDownload
? ListTile(
leading: const Icon(Icons.download),
title: Text(s.download),
title: Text(_s.download),
onTap: () => download(context, file),
)
: const SizedBox()
@@ -192,7 +192,8 @@ class _SFTPPageState extends State<SFTPPage> {
),
[
TextButton(
onPressed: () => Navigator.of(context).pop(), child: Text(s.cancel))
onPressed: () => Navigator.of(context).pop(),
child: Text(_s.cancel))
],
);
}
@@ -200,12 +201,12 @@ class _SFTPPageState extends State<SFTPPage> {
void download(BuildContext context, SftpName name) {
showRoundDialog(
context,
s.download,
Text('${s.dl2Local(name.filename)}\n${s.keepForeground}'),
_s.download,
Text('${_s.dl2Local(name.filename)}\n${_s.keepForeground}'),
[
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(s.cancel)),
child: Text(_s.cancel)),
TextButton(
onPressed: () async {
Navigator.of(context).pop();
@@ -229,12 +230,12 @@ class _SFTPPageState extends State<SFTPPage> {
Navigator.of(context).pop();
showRoundDialog(
context,
s.goSftpDlPage,
_s.goSftpDlPage,
const SizedBox(),
[
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(s.cancel),
child: Text(_s.cancel),
),
TextButton(
onPressed: () {
@@ -242,12 +243,12 @@ class _SFTPPageState extends State<SFTPPage> {
AppRoute(const SFTPDownloadingPage(), 'sftp downloading')
.go(context);
},
child: Text(s.ok),
child: Text(_s.ok),
)
],
);
},
child: Text(s.download),
child: Text(_s.download),
)
],
);
@@ -257,8 +258,8 @@ class _SFTPPageState extends State<SFTPPage> {
Navigator.of(context).pop();
showRoundDialog(
context,
s.attention,
Text(s.sureDelete(file.filename)),
_s.attention,
Text(_s.sureDelete(file.filename)),
[
TextButton(
onPressed: () => Navigator.of(context).pop(),
@@ -270,7 +271,7 @@ class _SFTPPageState extends State<SFTPPage> {
listDir();
},
child: Text(
s.delete,
_s.delete,
style: const TextStyle(color: Colors.red),
),
),
@@ -283,29 +284,29 @@ class _SFTPPageState extends State<SFTPPage> {
final textController = TextEditingController();
showRoundDialog(
context,
s.createFolder,
_s.createFolder,
TextField(
controller: textController,
decoration: InputDecoration(
labelText: s.name,
labelText: _s.name,
),
),
[
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(s.cancel),
child: Text(_s.cancel),
),
TextButton(
onPressed: () {
if (textController.text == '') {
showRoundDialog(
context,
s.attention,
Text(s.fieldMustNotEmpty),
_s.attention,
Text(_s.fieldMustNotEmpty),
[
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(s.ok)),
child: Text(_s.ok)),
],
);
return;
@@ -316,7 +317,7 @@ class _SFTPPageState extends State<SFTPPage> {
listDir();
},
child: Text(
s.ok,
_s.ok,
style: const TextStyle(color: Colors.red),
),
),
@@ -329,29 +330,29 @@ class _SFTPPageState extends State<SFTPPage> {
final textController = TextEditingController();
showRoundDialog(
context,
s.createFile,
_s.createFile,
TextField(
controller: textController,
decoration: InputDecoration(
labelText: s.name,
labelText: _s.name,
),
),
[
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(s.cancel),
child: Text(_s.cancel),
),
TextButton(
onPressed: () async {
if (textController.text == '') {
showRoundDialog(
context,
s.attention,
Text(s.fieldMustNotEmpty),
_s.attention,
Text(_s.fieldMustNotEmpty),
[
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(s.ok),
child: Text(_s.ok),
),
],
);
@@ -364,7 +365,7 @@ class _SFTPPageState extends State<SFTPPage> {
listDir();
},
child: Text(
s.ok,
_s.ok,
style: const TextStyle(color: Colors.red),
),
),
@@ -377,28 +378,28 @@ class _SFTPPageState extends State<SFTPPage> {
final textController = TextEditingController();
showRoundDialog(
context,
s.rename,
_s.rename,
TextField(
controller: textController,
decoration: InputDecoration(
labelText: s.name,
labelText: _s.name,
),
),
[
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(s.cancel)),
child: Text(_s.cancel)),
TextButton(
onPressed: () async {
if (textController.text == '') {
showRoundDialog(
context,
s.attention,
Text(s.fieldMustNotEmpty),
_s.attention,
Text(_s.fieldMustNotEmpty),
[
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(s.ok),
child: Text(_s.ok),
),
],
);
@@ -409,7 +410,7 @@ class _SFTPPageState extends State<SFTPPage> {
listDir();
},
child: Text(
s.rename,
_s.rename,
style: const TextStyle(color: Colors.red),
),
),
@@ -440,12 +441,12 @@ class _SFTPPageState extends State<SFTPPage> {
} catch (e) {
await showRoundDialog(
context,
s.error,
_s.error,
Text(e.toString()),
[
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(s.ok),
child: Text(_s.ok),
)
],
);
@@ -458,7 +459,7 @@ class _SFTPPageState extends State<SFTPPage> {
Widget _buildDestSelector() {
final str = _status.path?.path;
return ExpansionTile(
title: Text(_status.spi?.name ?? s.chooseDestination),
title: Text(_status.spi?.name ?? _s.chooseDestination),
subtitle: _status.selected
? str!.omitStartStr(style: const TextStyle(color: Colors.grey))
: null,