diff --git a/lib/core/extension/context/dialog.dart b/lib/core/extension/context/dialog.dart index 42e29079..1c2bbfa8 100644 --- a/lib/core/extension/context/dialog.dart +++ b/lib/core/extension/context/dialog.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:toolbox/core/extension/context/common.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/data/res/provider.dart'; import '../../../data/model/server/snippet.dart'; @@ -41,37 +41,35 @@ extension DialogX on BuildContext { String? user, ) async { if (!mounted) return null; - final s = S.of(this)!; return await showRoundDialog( - title: Text(user ?? s.pwd), + title: Text(user ?? l10n.pwd), child: Input( autoFocus: true, type: TextInputType.visiblePassword, obscureText: true, onSubmitted: (val) => pop(val.trim()), - label: s.pwd, + label: l10n.pwd, ), ); } void showSnippetDialog( - S s, void Function(Snippet s) onSelected, ) { if (Providers.snippet.snippets.isEmpty) { showRoundDialog( - child: Text(s.noSavedSnippet), + child: Text(l10n.noSavedSnippet), actions: [ TextButton( onPressed: () => pop(), - child: Text(s.ok), + child: Text(l10n.ok), ), TextButton( onPressed: () { pop(); AppRoute.snippetEdit().go(this); }, - child: Text(s.add), + child: Text(l10n.add), ) ], ); @@ -80,7 +78,7 @@ extension DialogX on BuildContext { var snippet = Providers.snippet.snippets.first; showRoundDialog( - title: Text(s.choose), + title: Text(l10n.choose), child: Picker( items: Providers.snippet.snippets.map((e) => Text(e.name)).toList(), onSelected: (idx) => snippet = Providers.snippet.snippets[idx], @@ -91,7 +89,7 @@ extension DialogX on BuildContext { pop(); onSelected(snippet); }, - child: Text(s.ok), + child: Text(l10n.ok), ) ], ); diff --git a/lib/core/extension/context/locale.dart b/lib/core/extension/context/locale.dart new file mode 100644 index 00000000..e6f163ef --- /dev/null +++ b/lib/core/extension/context/locale.dart @@ -0,0 +1,7 @@ +import 'package:flutter_gen/gen_l10n/l10n.dart'; + +late S _s; +S get l10n => _s; +set l10n(S s) { + _s = s; +} diff --git a/lib/core/update.dart b/lib/core/update.dart index 393f41b6..5d9bd01c 100644 --- a/lib/core/update.dart +++ b/lib/core/update.dart @@ -2,10 +2,10 @@ import 'dart:io'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:r_upgrade/r_upgrade.dart'; import 'package:toolbox/core/extension/context/common.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/context/snackbar.dart'; import 'package:toolbox/core/utils/platform/base.dart'; import 'package:toolbox/data/model/app/update.dart'; @@ -54,17 +54,15 @@ Future doUpdate(BuildContext context, {bool force = false}) async { return; } - final s = S.of(context); - final min = update.build.min.current; if (min != null && min > BuildData.build) { context.showRoundDialog( - child: Text(s?.updateTipTooLow(newest) ?? 'Update: $newest'), + child: Text(l10n.updateTipTooLow(newest)), actions: [ TextButton( - onPressed: () => _doUpdate(update, context, s), - child: Text(s?.ok ?? 'Ok'), + onPressed: () => _doUpdate(update, context), + child: Text(l10n.ok), ) ], ); @@ -72,13 +70,13 @@ Future doUpdate(BuildContext context, {bool force = false}) async { } context.showSnackBarWithAction( - '${s?.updateTip(newest) ?? "Update: $newest"} \n${update.changelog.current}', - s?.update ?? 'Update', - () => _doUpdate(update, context, s), + '${l10n.updateTip(newest)} \n${update.changelog.current}', + l10n.update, + () => _doUpdate(update, context), ); } -Future _doUpdate(AppUpdate update, BuildContext context, S? s) async { +Future _doUpdate(AppUpdate update, BuildContext context) async { final url = update.url.current; if (url == null) return; @@ -91,11 +89,11 @@ Future _doUpdate(AppUpdate update, BuildContext context, S? s) async { await openUrl(url); } else { context.showRoundDialog( - child: Text(s?.platformNotSupportUpdate ?? 'Unsupported platform'), + child: Text(l10n.platformNotSupportUpdate), actions: [ TextButton( onPressed: () => context.pop(), - child: Text(s?.ok ?? 'Ok'), + child: Text(l10n.ok), ) ], ); diff --git a/lib/core/utils/misc.dart b/lib/core/utils/misc.dart index 454d5037..e07ddc0b 100644 --- a/lib/core/utils/misc.dart +++ b/lib/core/utils/misc.dart @@ -3,9 +3,9 @@ import 'package:crypto/crypto.dart'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:plain_notification_token/plain_notification_token.dart'; import 'package:share_plus/share_plus.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/utils/platform/base.dart'; import 'package:toolbox/data/res/provider.dart'; @@ -19,7 +19,7 @@ Future shareFiles(BuildContext context, List filePaths) async { if (filePaths.length == 1) { text = filePaths.first.split('/').last; } else { - text = '${filePaths.length} ${S.of(context)!.files}'; + text = '${filePaths.length} ${l10n.files}'; } Providers.app.moveBg = false; // ignore: deprecated_member_use diff --git a/lib/core/utils/rebuild.dart b/lib/core/utils/rebuild.dart index ae5fe931..f708cba6 100644 --- a/lib/core/utils/rebuild.dart +++ b/lib/core/utils/rebuild.dart @@ -5,23 +5,23 @@ class _RebuildNode implements ValueListenable { final List _listeners = []; _RebuildNode(); - + @override void addListener(VoidCallback listener) { _listeners.add(listener); } - + @override void removeListener(VoidCallback listener) { _listeners.remove(listener); } - + void rebuild() { for (var listener in _listeners) { listener(); } } - + @override Null get value => null; } @@ -30,4 +30,4 @@ class RebuildNodes { const RebuildNodes._(); static final _RebuildNode app = _RebuildNode(); -} \ No newline at end of file +} diff --git a/lib/data/model/app/menu.dart b/lib/data/model/app/menu.dart index a300705e..976155fc 100644 --- a/lib/data/model/app/menu.dart +++ b/lib/data/model/app/menu.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; enum ServerTabMenuType { terminal, @@ -27,20 +27,20 @@ enum ServerTabMenuType { } } - String text(S s) { + String get toStr { switch (this) { case ServerTabMenuType.sftp: return 'SFTP'; case ServerTabMenuType.snippet: - return s.snippet; + return l10n.snippet; case ServerTabMenuType.pkg: - return s.pkg; + return l10n.pkg; case ServerTabMenuType.docker: return 'Docker'; case ServerTabMenuType.process: - return s.process; + return l10n.process; case ServerTabMenuType.terminal: - return s.terminal; + return l10n.terminal; } } } @@ -89,26 +89,26 @@ enum DockerMenuType { } } - String text(S s) { + String get toStr { switch (this) { case DockerMenuType.start: - return s.start; + return l10n.start; case DockerMenuType.stop: - return s.stop; + return l10n.stop; case DockerMenuType.restart: - return s.restart; + return l10n.restart; case DockerMenuType.rm: - return s.delete; + return l10n.delete; case DockerMenuType.logs: - return s.log; + return l10n.log; case DockerMenuType.terminal: - return s.terminal; + return l10n.terminal; // case DockerMenuType.stats: // return s.stats; } } - PopupMenuItem build(S s) => _build(this, icon, text(s)); + PopupMenuItem get widget => _build(this, icon, toStr); } PopupMenuItem _build(T t, IconData icon, String text) { diff --git a/lib/data/model/app/net_view.dart b/lib/data/model/app/net_view.dart index 32609bee..aa4fb10e 100644 --- a/lib/data/model/app/net_view.dart +++ b/lib/data/model/app/net_view.dart @@ -1,5 +1,5 @@ import 'package:hive_flutter/hive_flutter.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/data/model/server/server_status.dart'; part 'net_view.g.dart'; @@ -13,14 +13,14 @@ enum NetViewType { @HiveField(2) traffic; - String l10n(S s) { + String get toStr { switch (this) { case NetViewType.conn: - return s.conn; + return l10n.conn; case NetViewType.traffic: - return s.traffic; + return l10n.traffic; case NetViewType.speed: - return s.speed; + return l10n.speed; } } diff --git a/lib/data/model/ssh/virtual_key.dart b/lib/data/model/ssh/virtual_key.dart index 8ec41ae3..296a93ef 100644 --- a/lib/data/model/ssh/virtual_key.dart +++ b/lib/data/model/ssh/virtual_key.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:hive_flutter/hive_flutter.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:xterm/core.dart'; part 'virtual_key.g.dart'; @@ -148,12 +148,12 @@ enum VirtKey { } } - String? help(S s) { + String? get help { switch (this) { case VirtKey.sftp: - return s.virtKeyHelpSFTP; + return l10n.virtKeyHelpSFTP; case VirtKey.clipboard: - return s.virtKeyHelpClipboard; + return l10n.virtKeyHelpClipboard; default: return null; } diff --git a/lib/view/page/backup.dart b/lib/view/page/backup.dart index a51be93f..1b2cdc59 100644 --- a/lib/view/page/backup.dart +++ b/lib/view/page/backup.dart @@ -3,9 +3,9 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:toolbox/core/extension/context/common.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/context/snackbar.dart'; import 'package:toolbox/core/utils/platform/base.dart'; import 'package:toolbox/core/utils/rebuild.dart'; @@ -25,34 +25,33 @@ class BackupPage extends StatelessWidget { @override Widget build(BuildContext context) { - final s = S.of(context)!; return Scaffold( appBar: CustomAppBar( - title: Text(s.backupAndRestore, style: UIs.textSize18), + title: Text(l10n.backupAndRestore, style: UIs.textSize18), ), - body: _buildBody(context, s), + body: _buildBody(context), ); } - Widget _buildBody(BuildContext context, S s) { + Widget _buildBody(BuildContext context) { return Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ - if (isMacOS || isIOS) _buildIcloudSync(context, s), + if (isMacOS || isIOS) _buildIcloudSync(context), UIs.height13, Padding( padding: const EdgeInsets.all(37), child: Text( - s.backupTip, + l10n.backupTip, textAlign: TextAlign.center, ), ), UIs.height77, _buildCard( - s.restore, + l10n.restore, Icons.download, - () => _onRestore(context, s), + () => _onRestore(context), ), UIs.height13, const SizedBox( @@ -61,7 +60,7 @@ class BackupPage extends StatelessWidget { ), UIs.height13, _buildCard( - s.backup, + l10n.backup, Icons.save, () async { await Backup.backup(); @@ -96,7 +95,7 @@ class BackupPage extends StatelessWidget { ); } - Widget _buildIcloudSync(BuildContext context, S s) { + Widget _buildIcloudSync(BuildContext context) { return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -121,19 +120,19 @@ class BackupPage extends StatelessWidget { ); } - Future _onRestore(BuildContext context, S s) async { + Future _onRestore(BuildContext context) async { final path = await pickOneFile(); if (path == null) return; final file = File(path); if (!await file.exists()) { - context.showSnackBar(s.fileNotExist(path)); + context.showSnackBar(l10n.fileNotExist(path)); return; } final text = await file.readAsString(); if (text.isEmpty) { - context.showSnackBar(s.fieldMustNotEmpty); + context.showSnackBar(l10n.fieldMustNotEmpty); return; } @@ -141,17 +140,17 @@ class BackupPage extends StatelessWidget { context.showLoadingDialog(); final backup = await compute(Backup.fromJsonString, text.trim()); if (backupFormatVersion != backup.version) { - context.showSnackBar(s.backupVersionNotMatch); + context.showSnackBar(l10n.backupVersionNotMatch); return; } await context.showRoundDialog( - title: Text(s.restore), - child: Text(s.restoreSureWithDate(backup.date)), + title: Text(l10n.restore), + child: Text(l10n.restoreSureWithDate(backup.date)), actions: [ TextButton( onPressed: () => context.pop(), - child: Text(s.cancel), + child: Text(l10n.cancel), ), TextButton( onPressed: () async { @@ -159,7 +158,7 @@ class BackupPage extends StatelessWidget { context.pop(); RebuildNodes.app.rebuild(); }, - child: Text(s.ok), + child: Text(l10n.ok), ), ], ); diff --git a/lib/view/page/docker.dart b/lib/view/page/docker.dart index f817b1d1..521b8c3a 100644 --- a/lib/view/page/docker.dart +++ b/lib/view/page/docker.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:provider/provider.dart'; import 'package:toolbox/core/extension/context/common.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/context/snackbar.dart'; import 'package:toolbox/core/route.dart'; import 'package:toolbox/data/model/docker/image.dart'; @@ -33,7 +33,6 @@ class DockerManagePage extends StatefulWidget { class _DockerManagePageState extends State { final _textController = TextEditingController(); - late S _s; @override void dispose() { @@ -42,12 +41,6 @@ class _DockerManagePageState extends State { _textController.dispose(); } - @override - void didChangeDependencies() { - super.didChangeDependencies(); - _s = S.of(context)!; - } - @override void initState() { super.initState(); @@ -103,27 +96,27 @@ class _DockerManagePageState extends State { final nameCtrl = TextEditingController(); final argsCtrl = TextEditingController(); await context.showRoundDialog( - title: Text(_s.newContainer), + title: Text(l10n.newContainer), child: Column( mainAxisSize: MainAxisSize.min, children: [ Input( autoFocus: true, type: TextInputType.text, - label: _s.image, + label: l10n.image, hint: 'xxx:1.1', controller: imageCtrl, ), Input( type: TextInputType.text, controller: nameCtrl, - label: _s.containerName, + label: l10n.containerName, hint: 'xxx', ), Input( type: TextInputType.text, controller: argsCtrl, - label: _s.extraArgs, + label: l10n.extraArgs, hint: '-p 2222:22 -v ~/.xxx/:/xxx', ), ], @@ -131,7 +124,7 @@ class _DockerManagePageState extends State { actions: [ TextButton( onPressed: () => context.pop(), - child: Text(_s.cancel), + child: Text(l10n.cancel), ), TextButton( onPressed: () async { @@ -144,7 +137,7 @@ class _DockerManagePageState extends State { ), ); }, - child: Text(_s.ok), + child: Text(l10n.ok), ) ], ); @@ -152,12 +145,12 @@ class _DockerManagePageState extends State { Future _showAddCmdPreview(String cmd) async { await context.showRoundDialog( - title: Text(_s.preview), + title: Text(l10n.preview), child: Text(cmd), actions: [ TextButton( onPressed: () => context.pop(), - child: Text(_s.cancel), + child: Text(l10n.cancel), ), TextButton( onPressed: () async { @@ -166,10 +159,10 @@ class _DockerManagePageState extends State { final result = await Providers.docker.run(cmd); context.pop(); if (result != null) { - context.showSnackBar(result.message ?? _s.unknownError); + context.showSnackBar(result.message ?? l10n.unknownError); } }, - child: Text(_s.run), + child: Text(l10n.run), ) ], ); @@ -200,7 +193,7 @@ class _DockerManagePageState extends State { size: 37, ), const SizedBox(height: 27), - Text(Providers.docker.error?.message ?? _s.unknownError), + Text(Providers.docker.error?.message ?? l10n.unknownError), const SizedBox(height: 27), Padding( padding: const EdgeInsets.all(17), @@ -230,9 +223,9 @@ class _DockerManagePageState extends State { Widget _buildImage() { final items = [ ListTile( - title: Text(_s.imagesList), + title: Text(l10n.imagesList), subtitle: Text( - _s.dockerImagesFmt(Providers.docker.images!.length), + l10n.dockerImagesFmt(Providers.docker.images!.length), style: UIs.textGrey, ), ), @@ -256,12 +249,12 @@ class _DockerManagePageState extends State { void _showImageRmDialog(DockerImage e) { context.showRoundDialog( - title: Text(_s.attention), - child: Text(_s.sureDelete(e.repo)), + title: Text(l10n.attention), + child: Text(l10n.sureDelete(e.repo)), actions: [ TextButton( onPressed: () => context.pop(), - child: Text(_s.cancel), + child: Text(l10n.cancel), ), TextButton( onPressed: () async { @@ -270,10 +263,10 @@ class _DockerManagePageState extends State { 'docker rmi ${e.id} -f', ); if (result != null) { - context.showSnackBar(result.message ?? _s.unknownError); + context.showSnackBar(result.message ?? l10n.unknownError); } }, - child: Text(_s.ok, style: UIs.textRed), + child: Text(l10n.ok, style: UIs.textRed), ), ], ); @@ -299,14 +292,14 @@ class _DockerManagePageState extends State { switch (err.type) { case DockerErrType.notInstalled: return UrlText( - text: _s.installDockerWithUrl, - replace: _s.install, + text: l10n.installDockerWithUrl, + replace: l10n.install, ); case DockerErrType.noClient: - return Text(_s.waitConnection); + return Text(l10n.waitConnection); case DockerErrType.invalidVersion: return UrlText( - text: _s.invalidVersionHelp(Urls.appHelp), + text: l10n.invalidVersionHelp(Urls.appHelp), replace: 'Github', ); case DockerErrType.parseImages: @@ -330,8 +323,8 @@ class _DockerManagePageState extends State { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text(Providers.docker.edition ?? _s.unknown), - Text(Providers.docker.version ?? _s.unknown), + Text(Providers.docker.edition ?? l10n.unknown), + Text(Providers.docker.version ?? l10n.unknown), ], ), ); @@ -340,7 +333,7 @@ class _DockerManagePageState extends State { Widget _buildPs() { final items = [ ListTile( - title: Text(_s.containerStatus), + title: Text(l10n.containerStatus), subtitle: Text( _buildPsCardSubtitle(Providers.docker.items!), style: UIs.textGrey, @@ -367,17 +360,13 @@ class _DockerManagePageState extends State { Widget _buildMoreBtn(DockerPsItem dItem) { return PopupMenu( - items: DockerMenuType.items(dItem.running) - .map( - (e) => e.build(_s), - ) - .toList(), + items: DockerMenuType.items(dItem.running).map((e) => e.widget).toList(), onSelected: (DockerMenuType item) async { switch (item) { case DockerMenuType.rm: context.showRoundDialog( - title: Text(_s.attention), - child: Text(_s.sureDelete(dItem.name)), + title: Text(l10n.attention), + child: Text(l10n.sureDelete(dItem.name)), actions: [ TextButton( onPressed: () async { @@ -386,7 +375,7 @@ class _DockerManagePageState extends State { await Providers.docker.delete(dItem.containerId); context.pop(); }, - child: Text(_s.ok), + child: Text(l10n.ok), ) ], ); @@ -421,7 +410,7 @@ class _DockerManagePageState extends State { // case DockerMenuType.stats: // showRoundDialog( // context: context, - // title: Text(_s.stats), + // title: Text(l10n.stats), // child: Text( // 'CPU: ${dItem.cpu}\n' // 'Mem: ${dItem.mem}\n' @@ -431,7 +420,7 @@ class _DockerManagePageState extends State { // actions: [ // TextButton( // onPressed: () => context.pop(), - // child: Text(_s.ok), + // child: Text(l10n.ok), // ), // ], // ); @@ -445,9 +434,9 @@ class _DockerManagePageState extends State { final runningCount = running.where((element) => element.running).length; final stoped = running.length - runningCount; if (stoped == 0) { - return _s.dockerStatusRunningFmt(runningCount); + return l10n.dockerStatusRunningFmt(runningCount); } - return _s.dockerStatusRunningAndStoppedFmt(runningCount, stoped); + return l10n.dockerStatusRunningAndStoppedFmt(runningCount, stoped); } Widget _buildEditHost() { @@ -456,7 +445,7 @@ class _DockerManagePageState extends State { children.add(Padding( padding: const EdgeInsets.fromLTRB(17, 17, 17, 0), child: Text( - _s.dockerEmptyRunningItems, + l10n.dockerEmptyRunningItems, textAlign: TextAlign.center, ), )); @@ -464,7 +453,7 @@ class _DockerManagePageState extends State { children.add( TextButton( onPressed: _showEditHostDialog, - child: Text(_s.dockerEditHost), + child: Text(l10n.dockerEditHost), ), ); return Column( @@ -477,7 +466,7 @@ class _DockerManagePageState extends State { final host = Stores.docker.fetch(id) ?? 'unix:///run/user/1000/docker.sock'; final ctrl = TextEditingController(text: host); await context.showRoundDialog( - title: Text(_s.dockerEditHost), + title: Text(l10n.dockerEditHost), child: Input( maxLines: 1, controller: ctrl, @@ -486,7 +475,7 @@ class _DockerManagePageState extends State { actions: [ TextButton( onPressed: () => _onSaveDockerHost(ctrl.text), - child: Text(_s.ok), + child: Text(l10n.ok), ), ], ); diff --git a/lib/view/page/editor.dart b/lib/view/page/editor.dart index d2c88626..867ae6cb 100644 --- a/lib/view/page/editor.dart +++ b/lib/view/page/editor.dart @@ -3,12 +3,12 @@ import 'dart:io'; import 'package:code_text_field/code_text_field.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_highlight/theme_map.dart'; import 'package:flutter_highlight/themes/a11y-light.dart'; import 'package:flutter_highlight/themes/monokai.dart'; import 'package:toolbox/core/extension/context/common.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/utils/misc.dart'; import 'package:toolbox/data/res/highlight.dart'; import 'package:toolbox/data/res/store.dart'; @@ -47,7 +47,6 @@ class _EditorPageState extends State { late CodeController _controller; late Map _codeTheme; - late S _s; late final _textStyle = TextStyle(fontSize: Stores.setting.editorFontSize.fetch()); @@ -77,7 +76,6 @@ class _EditorPageState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - _s = S.of(context)!; if (context.isDark) { _codeTheme = @@ -126,8 +124,8 @@ class _EditorPageState extends State { return CustomAppBar( centerTitle: true, title: TwoLineText( - up: widget.title ?? getFileName(widget.path) ?? _s.unknown, - down: _s.editor, + up: widget.title ?? getFileName(widget.path) ?? l10n.unknown, + down: l10n.editor, ), actions: [ PopupMenuButton( diff --git a/lib/view/page/full_screen.dart b/lib/view/page/full_screen.dart index 3b054e49..96dd6f26 100644 --- a/lib/view/page/full_screen.dart +++ b/lib/view/page/full_screen.dart @@ -4,9 +4,9 @@ import 'dart:math'; import 'package:after_layout/after_layout.dart'; import 'package:circle_chart/circle_chart.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:get_it/get_it.dart'; import 'package:provider/provider.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/route.dart'; import 'package:toolbox/data/model/server/disk.dart'; import 'package:toolbox/data/provider/server.dart'; @@ -31,7 +31,6 @@ class FullScreenPage extends StatefulWidget { } class _FullScreenPageState extends State with AfterLayoutMixin { - late S _s; late MediaQueryData _media; late ThemeData _theme; late Timer _timer; @@ -63,7 +62,6 @@ class _FullScreenPageState extends State with AfterLayoutMixin { @override void didChangeDependencies() { super.didChangeDependencies(); - _s = S.of(context)!; _media = MediaQuery.of(context); _theme = Theme.of(context); } @@ -131,7 +129,7 @@ class _FullScreenPageState extends State with AfterLayoutMixin { child: TextButton( onPressed: () => AppRoute.serverEdit().go(context), child: Text( - _s.addAServer, + l10n.addAServer, style: const TextStyle(fontSize: 27), )), ); @@ -143,7 +141,7 @@ class _FullScreenPageState extends State with AfterLayoutMixin { final id = pro.serverOrder[idx]; final s = pro.servers[id]; if (s == null) { - return Center(child: Text(_s.noClient)); + return Center(child: Text(l10n.noClient)); } return _buildRealServerCard(s.status, s.state, s.spi); }, @@ -272,25 +270,25 @@ class _FullScreenPageState extends State with AfterLayoutMixin { ) { switch (cs) { case ServerState.disconnected: - return _s.disconnected; + return l10n.disconnected; case ServerState.connected: final tempStr = temp == null ? '' : '${temp.toStringAsFixed(1)}°C'; final items = [tempStr, upTime]; final str = items.where((element) => element.isNotEmpty).join(' | '); - if (str.isEmpty) return _s.serverTabLoading; + if (str.isEmpty) return l10n.serverTabLoading; return str; case ServerState.connecting: - return _s.serverTabConnecting; + return l10n.serverTabConnecting; case ServerState.failed: if (failedInfo == null) { - return _s.serverTabFailed; + return l10n.serverTabFailed; } if (failedInfo.contains('encypted')) { - return _s.serverTabPlzSave; + return l10n.serverTabPlzSave; } return failedInfo; default: - return _s.serverTabUnkown; + return l10n.serverTabUnkown; } } diff --git a/lib/view/page/home.dart b/lib/view/page/home.dart index 30f63dcc..df59f393 100644 --- a/lib/view/page/home.dart +++ b/lib/view/page/home.dart @@ -7,6 +7,7 @@ import 'package:get_it/get_it.dart'; import 'package:toolbox/core/channel/bg_run.dart'; import 'package:toolbox/core/channel/home_widget.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/utils/platform/auth.dart'; import 'package:toolbox/core/utils/platform/base.dart'; import 'package:toolbox/data/res/github_id.dart'; @@ -44,7 +45,6 @@ class _HomePageState extends State late final PageController _pageController; final _selectIndex = ValueNotifier(0); - late S _s; bool _switchingPage = false; bool _isAuthing = false; @@ -65,7 +65,7 @@ class _HomePageState extends State @override void didChangeDependencies() { super.didChangeDependencies(); - _s = S.of(context)!; + l10n = S.of(context)!; } @override @@ -133,7 +133,7 @@ class _HomePageState extends State final actions = [ IconButton( icon: const Icon(Icons.developer_mode, size: 23), - tooltip: _s.debug, + tooltip: l10n.debug, onPressed: () => AppRoute.debug().go(context), ), ]; @@ -182,12 +182,12 @@ class _HomePageState extends State destinations: [ NavigationDestination( icon: const Icon(Icons.cloud_outlined), - label: _s.server, + label: l10n.server, selectedIcon: const Icon(Icons.cloud), ), NavigationDestination( icon: const Icon(Icons.snippet_folder_outlined), - label: _s.snippet, + label: l10n.snippet, selectedIcon: const Icon(Icons.snippet_folder), ), const NavigationDestination( @@ -232,28 +232,28 @@ class _HomePageState extends State children: [ ListTile( leading: const Icon(Icons.settings), - title: Text(_s.setting), + title: Text(l10n.setting), onTap: () => AppRoute.settings().go(context), onLongPress: _onLongPressSetting, ), ListTile( leading: const Icon(Icons.vpn_key), - title: Text(_s.privateKey), + title: Text(l10n.privateKey), onTap: () => AppRoute.keyList().go(context), ), ListTile( leading: const Icon(Icons.file_open), - title: Text(_s.files), + title: Text(l10n.files), onTap: () => AppRoute.localStorage().go(context), ), ListTile( leading: const Icon(Icons.import_export), - title: Text(_s.backupAndRestore), + title: Text(l10n.backupAndRestore), onTap: () => AppRoute.backup().go(context), ), ListTile( leading: const Icon(Icons.text_snippet), - title: Text('${_s.about} & ${_s.feedback}'), + title: Text('${l10n.about} & ${l10n.feedback}'), onTap: _showAboutDialog, ) ].map((e) => RoundRectCard(e)).toList(), @@ -263,7 +263,7 @@ class _HomePageState extends State void _showAboutDialog() { context.showRoundDialog( - title: Text(_s.about), + title: Text(l10n.about), child: _buildAboutContent(), actions: [ TextButton( @@ -272,11 +272,11 @@ class _HomePageState extends State ), TextButton( onPressed: () => openUrl(Urls.appHelp), - child: Text(_s.feedback), + child: Text(l10n.feedback), ), TextButton( onPressed: () => showLicensePage(context: context), - child: Text(_s.license), + child: Text(l10n.license), ), ], ); @@ -289,12 +289,12 @@ class _HomePageState extends State crossAxisAlignment: CrossAxisAlignment.start, children: [ UrlText( - text: _s.madeWithLove(Urls.myGithub), + text: l10n.madeWithLove(Urls.myGithub), replace: 'lollipopkit', ), UIs.height13, // Use [UrlText] for same text style - Text(_s.aboutThanks), + Text(l10n.aboutThanks), UIs.height13, const Text('Contributors:'), ...GithubIds.contributors.map( @@ -365,7 +365,7 @@ class _HomePageState extends State final result = await AppRoute.editor( text: text, langCode: 'json', - title: _s.setting, + title: l10n.setting, ).go(context); if (result == null) { return; @@ -380,8 +380,8 @@ class _HomePageState extends State } } catch (e, trace) { context.showRoundDialog( - title: Text(_s.error), - child: Text('${_s.save}:\n$e'), + title: Text(l10n.error), + child: Text('${l10n.save}:\n$e'), ); Loggers.app.warning('Update json settings failed', e, trace); } @@ -391,7 +391,7 @@ class _HomePageState extends State if (Stores.setting.useBioAuth.fetch()) { if (!_isAuthing) { _isAuthing = true; - BioAuth.auth(_s.authRequired).then( + BioAuth.auth(l10n.authRequired).then( (val) { switch (val) { case AuthResult.success: diff --git a/lib/view/page/ping.dart b/lib/view/page/ping.dart index c93509c9..37f3e24a 100644 --- a/lib/view/page/ping.dart +++ b/lib/view/page/ping.dart @@ -2,9 +2,9 @@ import 'dart:async'; import 'package:after_layout/after_layout.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:toolbox/core/extension/context/common.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/context/snackbar.dart'; import 'package:toolbox/core/extension/uint8list.dart'; import 'package:toolbox/core/utils/misc.dart'; @@ -31,8 +31,6 @@ class _PingPageState extends State with AutomaticKeepAliveClientMixin, AfterLayoutMixin { late TextEditingController _textEditingController; final _results = ValueNotifier([]); - late S _s; - bool get isInit => _results.value.isEmpty; @override @@ -41,12 +39,6 @@ class _PingPageState extends State _textEditingController = TextEditingController(text: ''); } - @override - void didChangeDependencies() { - super.didChangeDependencies(); - _s = S.of(context)!; - } - @override void dispose() { super.dispose(); @@ -71,16 +63,16 @@ class _PingPageState extends State heroTag: 'ping', onPressed: () { context.showRoundDialog( - title: Text(_s.choose), + title: Text(l10n.choose), child: Input( autoFocus: true, controller: _textEditingController, - hint: _s.inputDomainHere, + hint: l10n.inputDomainHere, maxLines: 1, onSubmitted: (_) => _doPing(), ), actions: [ - TextButton(onPressed: _doPing, child: Text(_s.ok)), + TextButton(onPressed: _doPing, child: Text(l10n.ok)), ], ); }, @@ -94,12 +86,12 @@ class _PingPageState extends State await doPing(); } catch (e) { context.showRoundDialog( - title: Text(_s.error), + title: Text(l10n.error), child: Text(e.toString()), actions: [ TextButton( onPressed: () => copy2Clipboard(e.toString()), - child: Text(_s.copy), + child: Text(l10n.copy), ), ], ); @@ -111,7 +103,7 @@ class _PingPageState extends State if (isInit) { return Center( child: Text( - _s.noResult, + l10n.noResult, style: const TextStyle(fontSize: 18), ), ); @@ -125,8 +117,8 @@ class _PingPageState extends State } Widget _buildResultItem(PingResult result) { - final unknown = _s.unknown; - final ms = _s.ms; + final unknown = l10n.unknown; + final ms = l10n.ms; return RoundRectCard( ListTile( contentPadding: const EdgeInsets.symmetric(vertical: 7, horizontal: 17), @@ -143,7 +135,7 @@ class _PingPageState extends State style: UIs.textSize11, ), trailing: Text( - '${_s.pingAvg}${result.statistic?.avg?.toStringAsFixed(2) ?? _s.unknown} $ms', + '${l10n.pingAvg}${result.statistic?.avg?.toStringAsFixed(2) ?? l10n.unknown} $ms', style: TextStyle( fontSize: 14, color: primaryColor, @@ -156,13 +148,13 @@ class _PingPageState extends State String _buildPingSummary(PingResult result, String unknown, String ms) { final ip = result.ip ?? unknown; if (result.results == null || result.results!.isEmpty) { - return '$ip - ${_s.noResult}'; + return '$ip - ${l10n.noResult}'; } final ttl = result.results?.first.ttl ?? unknown; final loss = result.statistic?.loss ?? unknown; final min = result.statistic?.min ?? unknown; final max = result.statistic?.max ?? unknown; - return '$ip\n${_s.ttl}: $ttl, ${_s.loss}: $loss%\n${_s.min}: $min $ms, ${_s.max}: $max $ms'; + return '$ip\n${l10n.ttl}: $ttl, ${l10n.loss}: $loss%\n${l10n.min}: $min $ms, ${l10n.max}: $max $ms'; } Future doPing() async { @@ -170,18 +162,18 @@ class _PingPageState extends State _results.value.clear(); final target = _textEditingController.text.trim(); if (target.isEmpty) { - context.showSnackBar(_s.pingInputIP); + context.showSnackBar(l10n.pingInputIP); return; } if (Providers.server.servers.isEmpty) { - context.showSnackBar(_s.pingNoServer); + context.showSnackBar(l10n.pingNoServer); return; } /// avoid ping command injection if (!targetReg.hasMatch(target)) { - context.showSnackBar(_s.pingInputIP); + context.showSnackBar(l10n.pingInputIP); return; } diff --git a/lib/view/page/private_key/edit.dart b/lib/view/page/private_key/edit.dart index cf1af09f..ff779272 100644 --- a/lib/view/page/private_key/edit.dart +++ b/lib/view/page/private_key/edit.dart @@ -3,9 +3,9 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:toolbox/core/extension/context/common.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/context/snackbar.dart'; import 'package:toolbox/core/extension/numx.dart'; import 'package:toolbox/core/utils/misc.dart'; @@ -38,7 +38,6 @@ class _PrivateKeyEditPageState extends State { final _pwdNode = FocusNode(); late FocusScopeNode _focusScope; - late S _s; Widget? _loading; @@ -73,7 +72,6 @@ class _PrivateKeyEditPageState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - _s = S.of(context)!; _focusScope = FocusScope.of(context); } @@ -89,11 +87,11 @@ class _PrivateKeyEditPageState extends State { PreferredSizeWidget _buildAppBar() { final actions = [ IconButton( - tooltip: _s.delete, + tooltip: l10n.delete, onPressed: () { context.showRoundDialog( - title: Text(_s.attention), - child: Text(_s.sureDelete(widget.pki!.id)), + title: Text(l10n.attention), + child: Text(l10n.sureDelete(widget.pki!.id)), actions: [ TextButton( onPressed: () { @@ -102,7 +100,7 @@ class _PrivateKeyEditPageState extends State { context.pop(); }, child: Text( - _s.ok, + l10n.ok, style: UIs.textRed, ), ), @@ -113,20 +111,20 @@ class _PrivateKeyEditPageState extends State { ) ]; return CustomAppBar( - title: Text(_s.edit, style: UIs.textSize18), + title: Text(l10n.edit, style: UIs.textSize18), actions: widget.pki == null ? null : actions, ); } Widget _buildFAB() { return FloatingActionButton( - tooltip: _s.save, + tooltip: l10n.save, onPressed: () async { final name = _nameController.text; final key = _keyController.text.trim(); final pwd = _pwdController.text; if (name.isEmpty || key.isEmpty) { - context.showSnackBar(_s.fieldMustNotEmpty); + context.showSnackBar(l10n.fieldMustNotEmpty); return; } FocusScope.of(context).unfocus(); @@ -165,7 +163,7 @@ class _PrivateKeyEditPageState extends State { type: TextInputType.text, node: _nameNode, onSubmitted: (_) => _focusScope.requestFocus(_keyNode), - label: _s.name, + label: l10n.name, icon: Icons.info, ), Input( @@ -175,26 +173,26 @@ class _PrivateKeyEditPageState extends State { type: TextInputType.text, node: _keyNode, onSubmitted: (_) => _focusScope.requestFocus(_pwdNode), - label: _s.privateKey, + label: l10n.privateKey, icon: Icons.vpn_key, ), TextButton( onPressed: () async { final path = await pickOneFile(); if (path == null) { - context.showSnackBar(_s.fieldMustNotEmpty); + context.showSnackBar(l10n.fieldMustNotEmpty); return; } final file = File(path); if (!file.existsSync()) { - context.showSnackBar(_s.fileNotExist(path)); + context.showSnackBar(l10n.fileNotExist(path)); return; } final size = (await file.stat()).size; if (size > Miscs.privateKeyMaxSize) { context.showSnackBar( - _s.fileTooLarge( + l10n.fileTooLarge( path, size.convertBytes, Miscs.privateKeyMaxSize.convertBytes, @@ -205,14 +203,14 @@ class _PrivateKeyEditPageState extends State { _keyController.text = await file.readAsString(); }, - child: Text(_s.pickFile), + child: Text(l10n.pickFile), ), Input( controller: _pwdController, type: TextInputType.text, node: _pwdNode, obscureText: true, - label: _s.pwd, + label: l10n.pwd, icon: Icons.password, ), SizedBox(height: MediaQuery.of(context).size.height * 0.1), diff --git a/lib/view/page/private_key/list.dart b/lib/view/page/private_key/list.dart index 698ddbc8..3c4db0c3 100644 --- a/lib/view/page/private_key/list.dart +++ b/lib/view/page/private_key/list.dart @@ -2,10 +2,10 @@ import 'dart:io'; import 'dart:async'; import 'package:after_layout/after_layout.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:provider/provider.dart'; import 'package:toolbox/core/extension/context/common.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/utils/platform/base.dart'; import 'package:toolbox/core/utils/platform/path.dart'; import 'package:toolbox/data/res/store.dart'; @@ -26,19 +26,11 @@ class PrivateKeysListPage extends StatefulWidget { class _PrivateKeyListState extends State with AfterLayoutMixin { - late S _s; - - @override - void didChangeDependencies() { - super.didChangeDependencies(); - _s = S.of(context)!; - } - @override Widget build(BuildContext context) { return Scaffold( appBar: CustomAppBar( - title: Text(_s.privateKey, style: UIs.textSize18), + title: Text(l10n.privateKey, style: UIs.textSize18), ), body: _buildBody(), floatingActionButton: FloatingActionButton( @@ -53,7 +45,7 @@ class _PrivateKeyListState extends State builder: (_, key, __) { if (key.pkis.isEmpty) { return Center( - child: Text(_s.noSavedPrivateKey), + child: Text(l10n.noSavedPrivateKey), ); } return ListView.builder( @@ -71,7 +63,7 @@ class _PrivateKeyListState extends State ), ), title: Text(item.id), - subtitle: Text(item.type ?? _s.unknown, style: UIs.textGrey), + subtitle: Text(item.type ?? l10n.unknown, style: UIs.textGrey), onTap: () => AppRoute.keyEdit(pki: item).go(context), trailing: const Icon(Icons.edit), ), @@ -94,19 +86,19 @@ class _PrivateKeyListState extends State key: idRsaFile.readAsStringSync(), ); context.showRoundDialog( - title: Text(_s.attention), - child: Text(_s.addSystemPrivateKeyTip), + title: Text(l10n.attention), + child: Text(l10n.addSystemPrivateKeyTip), actions: [ TextButton( onPressed: () { context.pop(); AppRoute.keyEdit(pki: sysPk).go(context); }, - child: Text(_s.ok), + child: Text(l10n.ok), ), TextButton( onPressed: () => Navigator.pop(context), - child: Text(_s.cancel), + child: Text(l10n.cancel), ), ], ); diff --git a/lib/view/page/process.dart b/lib/view/page/process.dart index 234e2621..c44bfcac 100644 --- a/lib/view/page/process.dart +++ b/lib/view/page/process.dart @@ -2,9 +2,9 @@ import 'dart:async'; import 'package:dartssh2/dartssh2.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:toolbox/core/extension/context/common.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/context/snackbar.dart'; import 'package:toolbox/core/extension/uint8list.dart'; import 'package:toolbox/core/utils/misc.dart'; @@ -28,7 +28,6 @@ class ProcessPage extends StatefulWidget { } class _ProcessPageState extends State { - late S _s; late Timer _timer; late MediaQueryData _media; @@ -55,7 +54,6 @@ class _ProcessPageState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - _s = S.of(context)!; _media = MediaQuery.of(context); } @@ -63,7 +61,7 @@ class _ProcessPageState extends State { if (mounted) { final result = await _client?.run(AppShellFuncType.process.exec).string; if (result == null || result.isEmpty) { - context.showSnackBar(_s.noResult); + context.showSnackBar(l10n.noResult); return; } _result = PsResult.parse(result, sort: _procSortMode); @@ -110,12 +108,12 @@ class _ProcessPageState extends State { actions.add(IconButton( icon: const Icon(Icons.error), onPressed: () => context.showRoundDialog( - title: Text(_s.error), + title: Text(l10n.error), child: SingleChildScrollView(child: Text(_result.error!)), actions: [ TextButton( onPressed: () => copy2Clipboard(_result.error!), - child: Text(_s.copy), + child: Text(l10n.copy), ), ], ), @@ -134,7 +132,7 @@ class _ProcessPageState extends State { return Scaffold( appBar: CustomAppBar( centerTitle: true, - title: TwoLineText(up: widget.spi.name, down: _s.process), + title: TwoLineText(up: widget.spi.name, down: l10n.process), actions: actions, ), body: child, @@ -162,8 +160,8 @@ class _ProcessPageState extends State { onTap: () => _lastFocusId = proc.pid, onLongPress: () { context.showRoundDialog( - title: Text(_s.attention), - child: Text(_s.sureStop(proc.pid)), + title: Text(l10n.attention), + child: Text(l10n.sureStop(proc.pid)), actions: [ TextButton( onPressed: () async { @@ -171,7 +169,7 @@ class _ProcessPageState extends State { await _refresh(); context.pop(); }, - child: Text(_s.ok), + child: Text(l10n.ok), ), ], ); diff --git a/lib/view/page/server/detail.dart b/lib/view/page/server/detail.dart index 3665587a..2eea2d6b 100644 --- a/lib/view/page/server/detail.dart +++ b/lib/view/page/server/detail.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:provider/provider.dart'; import 'package:toolbox/core/extension/context/common.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/order.dart'; import 'package:toolbox/data/model/server/cpu.dart'; import 'package:toolbox/data/model/server/net_speed.dart'; @@ -34,7 +34,6 @@ class ServerDetailPage extends StatefulWidget { class _ServerDetailPageState extends State with SingleTickerProviderStateMixin { late MediaQueryData _media; - late S _s; final Order _cardsOrder = []; late final _textFactor = Stores.setting.textFactor.fetch(); @@ -58,7 +57,6 @@ class _ServerDetailPageState extends State void didChangeDependencies() { super.didChangeDependencies(); _media = MediaQuery.of(context); - _s = S.of(context)!; } @override @@ -74,7 +72,7 @@ class _ServerDetailPageState extends State if (s == null) { return Scaffold( body: Center( - child: Text(_s.noClient), + child: Text(l10n.noClient), ), ); } @@ -108,7 +106,7 @@ class _ServerDetailPageState extends State itemCount: buildFuncs ? _cardsOrder.length + 1 : _cardsOrder.length, itemBuilder: (context, index) { if (index == 0 && buildFuncs) { - return ServerFuncBtns(spi: widget.spi, s: _s, iconSize: 19); + return ServerFuncBtns(spi: widget.spi, iconSize: 19); } if (buildFuncs) index--; return _cardBuildMap[_cardsOrder[index]]?.call(si.status); @@ -369,7 +367,7 @@ class _ServerDetailPageState extends State if (ns.devices.isEmpty) { children.add(Center( child: Text( - _s.noInterface, + l10n.noInterface, style: const TextStyle(color: Colors.grey, fontSize: 13), ), )); diff --git a/lib/view/page/server/edit.dart b/lib/view/page/server/edit.dart index 49e1be7e..cf02406a 100644 --- a/lib/view/page/server/edit.dart +++ b/lib/view/page/server/edit.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:provider/provider.dart'; import 'package:toolbox/core/extension/context/common.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/context/snackbar.dart'; import 'package:toolbox/data/res/provider.dart'; @@ -40,7 +40,6 @@ class _ServerEditPageState extends State { final _usernameFocus = FocusNode(); late FocusScopeNode _focusScope; - late S _s; final _keyIdx = ValueNotifier(null); final _autoConnect = ValueNotifier(true); @@ -95,7 +94,6 @@ class _ServerEditPageState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - _s = S.of(context)!; _focusScope = FocusScope.of(context); } @@ -112,8 +110,8 @@ class _ServerEditPageState extends State { final delBtn = IconButton( onPressed: () { context.showRoundDialog( - title: Text(_s.attention), - child: Text(_s.sureToDeleteServer(widget.spi!.name)), + title: Text(l10n.attention), + child: Text(l10n.sureToDeleteServer(widget.spi!.name)), actions: [ TextButton( onPressed: () { @@ -121,7 +119,7 @@ class _ServerEditPageState extends State { context.pop(); context.pop(true); }, - child: Text(_s.ok, style: UIs.textRed), + child: Text(l10n.ok, style: UIs.textRed), ), ], ); @@ -130,7 +128,7 @@ class _ServerEditPageState extends State { ); final actions = widget.spi != null ? [delBtn] : null; return CustomAppBar( - title: Text(_s.edit, style: UIs.textSize18), + title: Text(l10n.edit, style: UIs.textSize18), actions: actions, ); } @@ -143,8 +141,8 @@ class _ServerEditPageState extends State { type: TextInputType.text, node: _nameFocus, onSubmitted: (_) => _focusScope.requestFocus(_ipFocus), - hint: _s.exampleName, - label: _s.name, + hint: l10n.exampleName, + label: l10n.name, icon: Icons.info, ), Input( @@ -152,7 +150,7 @@ class _ServerEditPageState extends State { type: TextInputType.text, onSubmitted: (_) => _focusScope.requestFocus(_portFocus), node: _ipFocus, - label: _s.host, + label: l10n.host, icon: Icons.computer, hint: 'example.com', ), @@ -161,7 +159,7 @@ class _ServerEditPageState extends State { type: TextInputType.number, node: _portFocus, onSubmitted: (_) => _focusScope.requestFocus(_usernameFocus), - label: _s.port, + label: l10n.port, icon: Icons.format_list_numbered, hint: '22', ), @@ -170,7 +168,7 @@ class _ServerEditPageState extends State { type: TextInputType.text, node: _usernameFocus, onSubmitted: (_) => _focusScope.requestFocus(_alterUrlFocus), - label: _s.user, + label: l10n.user, icon: Icons.account_box, hint: 'root', ), @@ -178,20 +176,19 @@ class _ServerEditPageState extends State { controller: _altUrlController, type: TextInputType.text, node: _alterUrlFocus, - label: _s.alterUrl, + label: l10n.alterUrl, icon: Icons.computer, hint: 'user@ip:port', ), TagEditor( tags: _tags, onChanged: (p0) => _tags = p0, - s: _s, allTags: [...Providers.server.tags], onRenameTag: Providers.server.renameTag, ), _buildAuth(), ListTile( - title: Text(_s.autoConnect), + title: Text(l10n.autoConnect), trailing: ValueBuilder( listenable: _autoConnect, build: () => Switch( @@ -215,7 +212,7 @@ class _ServerEditPageState extends State { Widget _buildAuth() { final switch_ = ListTile( - title: Text(_s.keyAuth), + title: Text(l10n.keyAuth), trailing: ValueBuilder( listenable: _keyIdx, build: () => Switch( @@ -243,9 +240,9 @@ class _ServerEditPageState extends State { controller: _passwordController, obscureText: true, type: TextInputType.text, - label: _s.pwd, + label: l10n.pwd, icon: Icons.password, - hint: _s.pwd, + hint: l10n.pwd, onSubmitted: (_) => _onSave(), )); } @@ -267,7 +264,7 @@ class _ServerEditPageState extends State { ), title: Text(e.id, textAlign: TextAlign.start), subtitle: Text( - e.type ?? _s.unknown, + e.type ?? l10n.unknown, textAlign: TextAlign.start, style: UIs.textGrey, ), @@ -276,7 +273,7 @@ class _ServerEditPageState extends State { }); tiles.add( ListTile( - title: Text(_s.addPrivateKey), + title: Text(l10n.addPrivateKey), contentPadding: EdgeInsets.zero, trailing: IconButton( icon: const Icon(Icons.add), @@ -319,21 +316,21 @@ class _ServerEditPageState extends State { void _onSave() async { if (_ipController.text == '') { - context.showSnackBar(_s.plzEnterHost); + context.showSnackBar(l10n.plzEnterHost); return; } if (_keyIdx.value == null && _passwordController.text == '') { final cancel = await context.showRoundDialog( - title: Text(_s.attention), - child: Text(_s.sureNoPwd), + title: Text(l10n.attention), + child: Text(l10n.sureNoPwd), actions: [ TextButton( onPressed: () => context.pop(false), - child: Text(_s.ok), + child: Text(l10n.ok), ), TextButton( onPressed: () => context.pop(true), - child: Text(_s.cancel), + child: Text(l10n.cancel), ) ], ); @@ -343,7 +340,7 @@ class _ServerEditPageState extends State { } // If [_pubKeyIndex] is -1, it means that the user has not selected if (_keyIdx.value == -1) { - context.showSnackBar(_s.plzSelectKey); + context.showSnackBar(l10n.plzSelectKey); return; } if (_usernameController.text.isEmpty) { diff --git a/lib/view/page/server/tab.dart b/lib/view/page/server/tab.dart index 5e832d9f..43a31a91 100644 --- a/lib/view/page/server/tab.dart +++ b/lib/view/page/server/tab.dart @@ -1,10 +1,10 @@ import 'package:after_layout/after_layout.dart'; import 'package:circle_chart/circle_chart.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:get_it/get_it.dart'; import 'package:provider/provider.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/media_queryx.dart'; import 'package:toolbox/core/extension/ssh_client.dart'; import 'package:toolbox/core/utils/platform/base.dart'; @@ -36,7 +36,6 @@ class ServerPage extends StatefulWidget { class _ServerPageState extends State with AutomaticKeepAliveClientMixin, AfterLayoutMixin { late MediaQueryData _media; - late S _s; final _flipedCardIds = {}; @@ -48,7 +47,6 @@ class _ServerPageState extends State super.didChangeDependencies(); _media = MediaQuery.of(context); _useDoubleColumn = _media.useDoubleColumn; - _s = S.of(context)!; } @override @@ -58,7 +56,7 @@ class _ServerPageState extends State body: _buildBody(), floatingActionButton: FloatingActionButton( onPressed: () => AppRoute.serverEdit().go(context), - tooltip: _s.addAServer, + tooltip: l10n.addAServer, heroTag: 'server', child: const Icon(Icons.add), ), @@ -74,7 +72,7 @@ class _ServerPageState extends State if (pro.serverOrder.isEmpty) { return Center( child: Text( - _s.serverTabEmpty, + l10n.serverTabEmpty, textAlign: TextAlign.center, ), ); @@ -108,7 +106,7 @@ class _ServerPageState extends State _tag = p0; }), initTag: _tag, - all: _s.all, + all: l10n.all, ); } @@ -294,7 +292,7 @@ class _ServerPageState extends State !Stores.setting.serverTabUseOldUI.fetch()) SizedBox( height: 27, - child: ServerFuncBtns(spi: spi, s: _s), + child: ServerFuncBtns(spi: spi), ), ]; } @@ -318,7 +316,7 @@ class _ServerPageState extends State ), ); } else if (Stores.setting.serverTabUseOldUI.fetch()) { - rightCorner = ServerFuncBtnsTopRight(spi: spi, s: _s); + rightCorner = ServerFuncBtnsTopRight(spi: spi); } return Padding( padding: const EdgeInsets.symmetric(horizontal: 7), @@ -361,7 +359,7 @@ class _ServerPageState extends State return GestureDetector( onTap: () => _showFailReason(ss), child: Text( - _s.viewErr, + l10n.viewErr, style: UIs.textSize11Grey, textScaleFactor: 1.0, ), @@ -376,14 +374,14 @@ class _ServerPageState extends State void _showFailReason(ServerStatus ss) { context.showRoundDialog( - title: Text(_s.error), + title: Text(l10n.error), child: SingleChildScrollView( - child: Text(ss.failedInfo ?? _s.unknownError), + child: Text(ss.failedInfo ?? l10n.unknownError), ), actions: [ TextButton( onPressed: () => copy2Clipboard(ss.failedInfo!), - child: Text(_s.copy), + child: Text(l10n.copy), ) ], ); @@ -478,25 +476,25 @@ class _ServerPageState extends State ) { switch (cs) { case ServerState.disconnected: - return _s.disconnected; + return l10n.disconnected; case ServerState.finished: final tempStr = temp == null ? '' : '${temp.toStringAsFixed(1)}°C'; final items = [tempStr, upTime]; final str = items.where((element) => element.isNotEmpty).join(' | '); - if (str.isEmpty) return _s.noResult; + if (str.isEmpty) return l10n.noResult; return str; case ServerState.loading: - return _s.serverTabLoading; + return l10n.serverTabLoading; case ServerState.connected: - return _s.connected; + return l10n.connected; case ServerState.connecting: - return _s.serverTabConnecting; + return l10n.serverTabConnecting; case ServerState.failed: if (failedInfo == null) { - return _s.serverTabFailed; + return l10n.serverTabFailed; } if (failedInfo.contains('encypted')) { - return _s.serverTabPlzSave; + return l10n.serverTabPlzSave; } return failedInfo; } diff --git a/lib/view/page/setting/android.dart b/lib/view/page/setting/android.dart index f204446f..75445525 100644 --- a/lib/view/page/setting/android.dart +++ b/lib/view/page/setting/android.dart @@ -1,10 +1,10 @@ import 'dart:convert'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:toolbox/core/extension/context/common.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/context/snackbar.dart'; import 'package:toolbox/data/res/store.dart'; import 'package:toolbox/view/widget/custom_appbar.dart'; @@ -20,15 +20,8 @@ class AndroidSettingsPage extends StatefulWidget { } class _AndroidSettingsPageState extends State { - late S _s; late SharedPreferences _sp; - @override - void didChangeDependencies() { - super.didChangeDependencies(); - _s = S.of(context)!; - } - @override void initState() { super.initState(); @@ -53,7 +46,7 @@ class _AndroidSettingsPageState extends State { Widget _buildBgRun() { return ListTile( - title: Text(_s.bgRun), + title: Text(l10n.bgRun), trailing: StoreSwitch(prop: Stores.setting.bgRun), ); } @@ -69,7 +62,7 @@ class _AndroidSettingsPageState extends State { map.forEach((key, value) { _sp.setString(key, value); }); - context.showSnackBar(_s.success); + context.showSnackBar(l10n.success); } catch (e) { context.showSnackBar(e.toString()); } @@ -77,7 +70,7 @@ class _AndroidSettingsPageState extends State { Widget _buildAndroidWidgetSharedPreference() { return ListTile( - title: Text(_s.homeWidgetUrlConfig), + title: Text(l10n.homeWidgetUrlConfig), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () { final data = {}; @@ -89,7 +82,7 @@ class _AndroidSettingsPageState extends State { }); final ctrl = TextEditingController(text: json.encode(data)); context.showRoundDialog( - title: Text(_s.homeWidgetUrlConfig), + title: Text(l10n.homeWidgetUrlConfig), child: Input( autoFocus: true, controller: ctrl, @@ -103,7 +96,7 @@ class _AndroidSettingsPageState extends State { onPressed: () { _saveWidgetSP(ctrl.text, data); }, - child: Text(_s.ok), + child: Text(l10n.ok), ), ], ); diff --git a/lib/view/page/setting/entry.dart b/lib/view/page/setting/entry.dart index 77df3def..62e7bf43 100644 --- a/lib/view/page/setting/entry.dart +++ b/lib/view/page/setting/entry.dart @@ -1,11 +1,12 @@ import 'dart:io'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_highlight/theme_map.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:provider/provider.dart'; import 'package:toolbox/core/extension/colorx.dart'; import 'package:toolbox/core/extension/context/common.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/context/snackbar.dart'; import 'package:toolbox/core/extension/locale.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; @@ -53,8 +54,6 @@ class _SettingPageState extends State { final _netViewTypeKey = GlobalKey>(); final _setting = Stores.setting; - late S _s; - final _selectedColorValue = ValueNotifier(0); final _nightMode = ValueNotifier(0); final _maxRetryCount = ValueNotifier(0); @@ -71,10 +70,9 @@ class _SettingPageState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - _s = S.of(context)!; final localeSettingVal = _setting.locale.fetch(); if (localeSettingVal.isEmpty) { - _localeCode.value = _s.localeName; + _localeCode.value = l10n.localeName; } else { _localeCode.value = localeSettingVal; } @@ -100,26 +98,27 @@ class _SettingPageState extends State { Widget build(BuildContext context) { return Scaffold( appBar: CustomAppBar( - title: Text(_s.setting), + title: Text(l10n.setting), actions: [ IconButton( onPressed: () => context.showRoundDialog( - title: Text(_s.attention), - child: Text(_s.sureDelete(_s.all)), + title: Text(l10n.attention), + child: Text(l10n.sureDelete(l10n.all)), actions: [ TextButton( onPressed: () { _setting.box.deleteAll(_setting.box.keys); context.pop(); - context.showSnackBar(_s.success); + context.showSnackBar(l10n.success); }, - child: Text(_s.ok, style: const TextStyle(color: Colors.red)), + child: + Text(l10n.ok, style: const TextStyle(color: Colors.red)), ), ], ), // onDoubleTap: () => context.showRoundDialog( - // title: Text(_s.attention), - // child: Text(_s.sureDelete(_s.all)), + // title: Text(l10n.attention), + // child: Text(l10n.sureDelete(l10n.all)), // actions: [ // TextButton( // onPressed: () { @@ -130,9 +129,9 @@ class _SettingPageState extends State { // Stores.snippet.box.deleteFromDisk(); // Stores.key.box.deleteFromDisk(); // context.pop(); - // context.showSnackBar(_s.success); + // context.showSnackBar(l10n.success); // }, - // child: Text(_s.ok, style: const TextStyle(color: Colors.red)), + // child: Text(l10n.ok, style: const TextStyle(color: Colors.red)), // ), // ], // ), @@ -145,13 +144,13 @@ class _SettingPageState extends State { children: [ _buildTitle('App'), _buildApp(), - _buildTitle(_s.server), + _buildTitle(l10n.server), _buildServer(), _buildTitle('SSH'), _buildSSH(), - _buildTitle(_s.editor), + _buildTitle(l10n.editor), _buildEditor(), - _buildTitle(_s.fullScreen), + _buildTitle(l10n.fullScreen), _buildFullScreen(), const SizedBox(height: 37), ], @@ -247,15 +246,15 @@ class _SettingPageState extends State { String display; if (app.newestBuild != null) { if (app.newestBuild! > BuildData.build) { - display = _s.versionHaveUpdate(app.newestBuild!); + display = l10n.versionHaveUpdate(app.newestBuild!); } else { - display = _s.versionUpdated(BuildData.build); + display = l10n.versionUpdated(BuildData.build); } } else { - display = _s.versionUnknownUpdate(BuildData.build); + display = l10n.versionUnknownUpdate(BuildData.build); } return ListTile( - title: Text(_s.autoCheckUpdate), + title: Text(l10n.autoCheckUpdate), subtitle: Text(display, style: UIs.textGrey), onTap: () => doUpdate(ctx, force: true), trailing: StoreSwitch(prop: _setting.autoCheckAppUpdate), @@ -269,17 +268,17 @@ class _SettingPageState extends State { 10, (index) => PopupMenuItem( value: index, - child: Text('$index ${_s.second}'), + child: Text('$index ${l10n.second}'), ), growable: false, ).toList(); return ListTile( title: Text( - _s.updateServerStatusInterval, + l10n.updateServerStatusInterval, ), subtitle: Text( - _s.willTakEeffectImmediately, + l10n.willTakEeffectImmediately, style: UIs.textGrey, ), onTap: () { @@ -296,11 +295,11 @@ class _SettingPageState extends State { _setting.serverStatusUpdateInterval.put(val); Providers.server.startAutoRefresh(); if (val == 0) { - context.showSnackBar(_s.updateIntervalEqual0); + context.showSnackBar(l10n.updateIntervalEqual0); } }, child: Text( - '${_updateInterval.value} ${_s.second}', + '${_updateInterval.value} ${l10n.second}', style: UIs.textSize15, ), ), @@ -317,17 +316,17 @@ class _SettingPageState extends State { width: 27, ), ), - title: Text(_s.primaryColorSeed), + title: Text(l10n.primaryColorSeed), onTap: () async { final ctrl = TextEditingController(text: primaryColor.toHex); await context.showRoundDialog( - title: Text(_s.primaryColorSeed), + title: Text(l10n.primaryColorSeed), child: StatefulBuilder(builder: (context, setState) { final children = [ /// Plugin [dynamic_color] is not supported on iOS if (!isIOS) ListTile( - title: Text(_s.followSystem), + title: Text(l10n.followSystem), trailing: StoreSwitch( prop: _setting.useSystemPrimaryColor, func: (_) => setState(() {}), @@ -356,7 +355,7 @@ class _SettingPageState extends State { actions: [ TextButton( onPressed: () => _onSaveColor(ctrl.text), - child: Text(_s.ok), + child: Text(l10n.ok), ), ]); }, @@ -366,7 +365,7 @@ class _SettingPageState extends State { void _onSaveColor(String s) { final color = s.hexToColor; if (color == null) { - context.showSnackBar(_s.failed); + context.showSnackBar(l10n.failed); return; } _selectedColorValue.value = color.value; @@ -388,7 +387,7 @@ class _SettingPageState extends State { // return ListTile( // title: Text( - // _s.launchPage, + // l10n.launchPage, // ), // onTap: () { // _startPageKey.currentState?.showButtonMenu(); @@ -421,16 +420,17 @@ class _SettingPageState extends State { 10, (index) => PopupMenuItem( value: index, - child: Text('$index ${_s.times}'), + child: Text('$index ${l10n.times}'), ), growable: false, ).toList(); - final help = - _maxRetryCount.value == 0 ? _s.maxRetryCountEqual0 : _s.canPullRefresh; + final help = _maxRetryCount.value == 0 + ? l10n.maxRetryCountEqual0 + : l10n.canPullRefresh; return ListTile( title: Text( - _s.maxRetryCount, + l10n.maxRetryCount, textAlign: TextAlign.start, ), subtitle: Text(help, style: UIs.textGrey), @@ -447,7 +447,7 @@ class _SettingPageState extends State { _setting.maxRetryCount.put(_maxRetryCount.value); }, child: Text( - '${_maxRetryCount.value} ${_s.times}', + '${_maxRetryCount.value} ${l10n.times}', style: UIs.textSize15, ), ), @@ -471,7 +471,7 @@ class _SettingPageState extends State { return ListTile( title: Text( - _s.themeMode, + l10n.themeMode, ), onTap: () { _themeKey.currentState?.showButtonMenu(); @@ -486,7 +486,7 @@ class _SettingPageState extends State { _nightMode.value = idx; _setting.themeMode.put(_nightMode.value); - RebuildNodes.app.rebuild(); + RebuildNodes.app.rebuild(); }, child: Text( _buildThemeModeStr(_nightMode.value), @@ -500,39 +500,39 @@ class _SettingPageState extends State { String _buildThemeModeStr(int n) { switch (n) { case 1: - return _s.light; + return l10n.light; case 2: - return _s.dark; + return l10n.dark; case 3: return 'AMOLED'; default: - return _s.auto; + return l10n.auto; } } Widget _buildFont() { final fontName = getFileName(_setting.fontPath.fetch()); return ListTile( - title: Text(_s.font), + title: Text(l10n.font), trailing: Text( - fontName ?? _s.notSelected, + fontName ?? l10n.notSelected, style: UIs.textSize15, ), onTap: () { context.showRoundDialog( - title: Text(_s.font), + title: Text(l10n.font), actions: [ TextButton( onPressed: () async => await _pickFontFile(), - child: Text(_s.pickFile), + child: Text(l10n.pickFile), ), TextButton( onPressed: () { _setting.fontPath.delete(); context.pop(); - RebuildNodes.app.rebuild(); + RebuildNodes.app.rebuild(); }, - child: Text(_s.clear), + child: Text(l10n.clear), ) ], ); @@ -554,17 +554,17 @@ class _SettingPageState extends State { } context.pop(); - RebuildNodes.app.rebuild(); + RebuildNodes.app.rebuild(); return; } - context.showSnackBar(_s.failed); + context.showSnackBar(l10n.failed); } Widget _buildTermFontSize() { return ValueBuilder( listenable: _termFontSize, build: () => ListTile( - title: Text(_s.fontSize), + title: Text(l10n.fontSize), trailing: Text( _termFontSize.value.toString(), style: UIs.textSize15, @@ -577,8 +577,8 @@ class _SettingPageState extends State { // Widget _buildDiskIgnorePath() { // final paths = _setting.diskIgnorePath.fetch(); // return ListTile( - // title: Text(_s.diskIgnorePath), - // trailing: Text(_s.edit, style: textSize15), + // title: Text(l10n.diskIgnorePath), + // trailing: Text(l10n.edit, style: textSize15), // onTap: () { // final ctrller = TextEditingController(text: json.encode(paths)); // void onSubmit() { @@ -586,7 +586,7 @@ class _SettingPageState extends State { // final list = List.from(json.decode(ctrller.text)); // _setting.diskIgnorePath.put(list); // context.pop(); - // showSnackBar(context, Text(_s.success)); + // showSnackBar(context, Text(l10n.success)); // } catch (e) { // showSnackBar(context, Text(e.toString())); // } @@ -594,7 +594,7 @@ class _SettingPageState extends State { // showRoundDialog( // context: context, - // title: Text(_s.diskIgnorePath), + // title: Text(l10n.diskIgnorePath), // child: Input( // autoFocus: true, // controller: ctrller, @@ -604,7 +604,7 @@ class _SettingPageState extends State { // onSubmitted: (_) => onSubmit(), // ), // actions: [ - // TextButton(onPressed: onSubmit, child: Text(_s.ok)), + // TextButton(onPressed: onSubmit, child: Text(l10n.ok)), // ], // ); // }, @@ -621,7 +621,7 @@ class _SettingPageState extends State { ) .toList(); return ListTile( - title: Text(_s.language), + title: Text(l10n.language), onTap: () { _localeKey.currentState?.showButtonMenu(); }, @@ -634,10 +634,10 @@ class _SettingPageState extends State { onSelected: (String idx) { _localeCode.value = idx; _setting.locale.put(idx); - RebuildNodes.app.rebuild(); + RebuildNodes.app.rebuild(); }, child: Text( - _s.languageName, + l10n.languageName, style: UIs.textSize15, ), ), @@ -647,7 +647,7 @@ class _SettingPageState extends State { Widget _buildSSHVirtualKeyAutoOff() { return ListTile( - title: Text(_s.sshVirtualKeyAutoOff), + title: Text(l10n.sshVirtualKeyAutoOff), subtitle: const Text('Ctrl & Alt', style: UIs.textGrey), trailing: StoreSwitch(prop: _setting.sshVirtualKeyAutoOff), ); @@ -663,7 +663,7 @@ class _SettingPageState extends State { }, ).toList(); return ListTile( - title: Text('${_s.light} ${_s.theme.toLowerCase()}'), + title: Text('${l10n.light} ${l10n.theme.toLowerCase()}'), trailing: ValueBuilder( listenable: _editorTheme, build: () => PopupMenuButton( @@ -696,7 +696,7 @@ class _SettingPageState extends State { }, ).toList(); return ListTile( - title: Text('${_s.dark} ${_s.theme.toLowerCase()}'), + title: Text('${l10n.dark} ${l10n.theme.toLowerCase()}'), trailing: ValueBuilder( listenable: _editorDarkTheme, build: () => PopupMenuButton( @@ -721,19 +721,18 @@ class _SettingPageState extends State { Widget _buildFullScreenSwitch() { return ListTile( - title: Text(_s.fullScreen), + title: Text(l10n.fullScreen), trailing: StoreSwitch( prop: _setting.fullScreen, - func: (_) => - RebuildNodes.app.rebuild(), + func: (_) => RebuildNodes.app.rebuild(), ), ); } Widget _buildFullScreenJitter() { return ListTile( - title: Text(_s.fullScreenJitter), - subtitle: Text(_s.fullScreenJitterHelp, style: UIs.textGrey), + title: Text(l10n.fullScreenJitter), + subtitle: Text(l10n.fullScreenJitterHelp, style: UIs.textGrey), trailing: StoreSwitch(prop: _setting.fullScreenJitter), ); } @@ -748,7 +747,7 @@ class _SettingPageState extends State { }).toList(); return ListTile( - title: Text(_s.rotateAngel), + title: Text(l10n.rotateAngel), onTap: () { _rotateQuarterKey.currentState?.showButtonMenu(); }, @@ -798,8 +797,8 @@ class _SettingPageState extends State { }, ).toList(); return ListTile( - title: Text(_s.keyboardType), - subtitle: Text(_s.keyboardCompatibility, style: UIs.textGrey), + title: Text(l10n.keyboardType), + subtitle: Text(l10n.keyboardCompatibility, style: UIs.textGrey), trailing: ValueBuilder( listenable: _keyboardType, build: () => PopupMenuButton( @@ -824,7 +823,7 @@ class _SettingPageState extends State { Widget _buildSSHVirtKeys() { return ListTile( - title: Text(_s.editVirtKeys), + title: Text(l10n.editVirtKeys), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () => AppRoute.sshVirtKeySetting().go(context), ); @@ -834,11 +833,11 @@ class _SettingPageState extends State { final items = NetViewType.values .map((e) => PopupMenuItem( value: e, - child: Text(e.l10n(_s)), + child: Text(e.toStr), )) .toList(); return ListTile( - title: Text(_s.netViewType), + title: Text(l10n.netViewType), trailing: ValueBuilder( listenable: _netViewType, build: () => PopupMenuButton( @@ -850,7 +849,7 @@ class _SettingPageState extends State { _setting.netViewType.put(idx); }, child: Text( - _netViewType.value.l10n(_s), + _netViewType.value.toStr, style: UIs.textSize15, ), ), @@ -863,18 +862,18 @@ class _SettingPageState extends State { Widget _buildDeleteServers() { return ListTile( - title: Text(_s.deleteServers), + title: Text(l10n.deleteServers), trailing: const Icon(Icons.delete_forever), onTap: () async { final all = Stores.server.box.keys.map( (e) => TextButton( onPressed: () => context.showRoundDialog( - title: Text(_s.attention), - child: Text(_s.sureDelete(e)), + title: Text(l10n.attention), + child: Text(l10n.sureDelete(e)), actions: [ TextButton( onPressed: () => Providers.server.delServer(e), - child: Text(_s.ok), + child: Text(l10n.ok), ) ], ), @@ -882,7 +881,7 @@ class _SettingPageState extends State { ), ); context.showRoundDialog>( - title: Text(_s.choose), + title: Text(l10n.choose), child: SingleChildScrollView( child: Column( mainAxisSize: MainAxisSize.min, @@ -896,30 +895,30 @@ class _SettingPageState extends State { Widget _buildMoveOutServerFuncBtns() { return ListTile( - title: Text(_s.moveOutServerFuncBtns), - subtitle: Text(_s.moveOutServerFuncBtnsHelp, style: UIs.textSize13Grey), + title: Text(l10n.moveOutServerFuncBtns), + subtitle: Text(l10n.moveOutServerFuncBtnsHelp, style: UIs.textSize13Grey), trailing: StoreSwitch(prop: _setting.moveOutServerTabFuncBtns), ); } Widget _buildServerOrder() { return ListTile( - title: Text(_s.serverOrder), - subtitle: Text('${_s.serverOrder} / ${_s.serverDetailOrder}', + title: Text(l10n.serverOrder), + subtitle: Text('${l10n.serverOrder} / ${l10n.serverDetailOrder}', style: UIs.textGrey), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () => context.showRoundDialog( - title: Text(_s.choose), + title: Text(l10n.choose), child: Column( mainAxisSize: MainAxisSize.min, children: [ ListTile( - title: Text(_s.serverOrder), + title: Text(l10n.serverOrder), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () => AppRoute.serverOrder().go(context), ), ListTile( - title: Text(_s.serverDetailOrder), + title: Text(l10n.serverDetailOrder), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () => AppRoute.serverDetailOrder().go(context), ), @@ -933,7 +932,7 @@ class _SettingPageState extends State { return ValueBuilder( listenable: _editorFontSize, build: () => ListTile( - title: Text(_s.fontSize), + title: Text(l10n.fontSize), trailing: Text( _editorFontSize.value.toString(), style: UIs.textSize15, @@ -954,7 +953,7 @@ class _SettingPageState extends State { final fontSize = double.tryParse(ctrller.text); if (fontSize == null) { context.showRoundDialog( - title: Text(_s.failed), + title: Text(l10n.failed), child: Text('Parsed failed: ${ctrller.text}'), ); return; @@ -964,7 +963,7 @@ class _SettingPageState extends State { } context.showRoundDialog( - title: Text(_s.fontSize), + title: Text(l10n.fontSize), child: Input( controller: ctrller, autoFocus: true, @@ -975,7 +974,7 @@ class _SettingPageState extends State { actions: [ TextButton( onPressed: onSave, - child: Text(_s.ok), + child: Text(l10n.ok), ), ], ); @@ -984,14 +983,14 @@ class _SettingPageState extends State { Widget _buildSftpRmrfDir() { return ListTile( title: const Text('rm -rf'), - subtitle: Text(_s.sftpRmrfDirSummary, style: UIs.textGrey), + subtitle: Text(l10n.sftpRmrfDirSummary, style: UIs.textGrey), trailing: StoreSwitch(prop: _setting.sftpRmrfDir), ); } // Widget _buildDoubleColumnServersPage() { // return ListTile( - // title: Text(_s.doubleColumnMode), + // title: Text(l10n.doubleColumnMode), // trailing: StoreSwitch(prop: _setting.doubleColumnServersPage), // ); // } @@ -1000,16 +999,16 @@ class _SettingPageState extends State { return FutureWidget( future: BioAuth.isAvail, loading: ListTile( - title: Text(_s.bioAuth), - subtitle: Text(_s.serverTabLoading, style: UIs.textGrey), + title: Text(l10n.bioAuth), + subtitle: Text(l10n.serverTabLoading, style: UIs.textGrey), ), error: (e, __) => ListTile( - title: Text(_s.bioAuth), - subtitle: Text('${_s.failed}: $e', style: UIs.textGrey), + title: Text(l10n.bioAuth), + subtitle: Text('${l10n.failed}: $e', style: UIs.textGrey), ), success: (can) { return ListTile( - title: Text(_s.bioAuth), + title: Text(l10n.bioAuth), subtitle: can ? null : const Text('Error: Bio auth is not available', @@ -1023,7 +1022,7 @@ class _SettingPageState extends State { return; } // Only auth when turn off (val == false) - final result = await BioAuth.auth(_s.authRequired); + final result = await BioAuth.auth(l10n.authRequired); // If failed, turn on again if (result != AuthResult.success) { Stores.setting.useBioAuth.put(true); @@ -1039,7 +1038,7 @@ class _SettingPageState extends State { Widget _buildPlatformSetting() { return ListTile( - title: Text('${OS.type} ${_s.setting}'), + title: Text('${OS.type} ${l10n.setting}'), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () { switch (OS.type) { diff --git a/lib/view/page/setting/ios.dart b/lib/view/page/setting/ios.dart index 78ba4bce..1a250b76 100644 --- a/lib/view/page/setting/ios.dart +++ b/lib/view/page/setting/ios.dart @@ -1,8 +1,8 @@ import 'dart:convert'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/context/snackbar.dart'; import 'package:toolbox/core/route.dart'; import 'package:toolbox/core/utils/misc.dart'; @@ -24,18 +24,10 @@ class IOSSettingsPage extends StatefulWidget { } class _IOSSettingsPageState extends State { - late S _s; - final _pushToken = ValueNotifier(null); final wc = WatchConnectivity(); - @override - void didChangeDependencies() { - super.didChangeDependencies(); - _s = S.of(context)!; - } - @override Widget build(BuildContext context) { return Scaffold( @@ -55,9 +47,7 @@ class _IOSSettingsPageState extends State { Widget _buildPushToken() { return ListTile( - title: Text( - _s.pushToken, - ), + title: Text(l10n.pushToken), trailing: IconButton( icon: const Icon(Icons.copy), alignment: Alignment.centerRight, @@ -65,21 +55,21 @@ class _IOSSettingsPageState extends State { onPressed: () { if (_pushToken.value != null) { copy2Clipboard(_pushToken.value!); - context.showSnackBar(_s.success); + context.showSnackBar(l10n.success); } else { - context.showSnackBar(_s.getPushTokenFailed); + context.showSnackBar(l10n.getPushTokenFailed); } }, ), subtitle: FutureWidget( future: getToken(), - loading: Text(_s.gettingToken), - error: (error, trace) => Text('${_s.error}: $error'), - noData: Text(_s.nullToken), + loading: Text(l10n.gettingToken), + error: (error, trace) => Text('${l10n.error}: $error'), + noData: Text(l10n.nullToken), success: (text) { _pushToken.value = text; return Text( - text ?? _s.nullToken, + text ?? l10n.nullToken, style: UIs.textGrey, overflow: TextOverflow.ellipsis, maxLines: 1, @@ -91,8 +81,8 @@ class _IOSSettingsPageState extends State { Widget _buildAutoUpdateHomeWidget() { return ListTile( - title: Text(_s.autoUpdateHomeWidget), - subtitle: Text(_s.whenOpenApp, style: UIs.textGrey), + title: Text(l10n.autoUpdateHomeWidget), + subtitle: Text(l10n.whenOpenApp, style: UIs.textGrey), trailing: StoreSwitch(prop: Stores.setting.autoUpdateHomeWidget), ); } @@ -110,14 +100,14 @@ class _IOSSettingsPageState extends State { Loggers.app.warning('WatchOS error', e, trace); return ListTile( title: const Text('Watch app'), - subtitle: Text('${_s.error}: $e', style: UIs.textGrey), + subtitle: Text('${l10n.error}: $e', style: UIs.textGrey), ); }, success: (ctx) { if (ctx == null) { return ListTile( title: const Text('Watch app'), - subtitle: Text(_s.watchNotPaired, style: UIs.textGrey), + subtitle: Text(l10n.watchNotPaired, style: UIs.textGrey), ); } return ListTile( @@ -146,8 +136,8 @@ class _IOSSettingsPageState extends State { await wc.updateApplicationContext(newCtx); } catch (e, trace) { context.showRoundDialog( - title: Text(_s.error), - child: Text('${_s.save}:\n$e'), + title: Text(l10n.error), + child: Text('${l10n.save}:\n$e'), ); Loggers.app.warning('Update watch config failed', e, trace); } diff --git a/lib/view/page/setting/srv_detail_seq.dart b/lib/view/page/setting/srv_detail_seq.dart index 92088070..d85673cd 100644 --- a/lib/view/page/setting/srv_detail_seq.dart +++ b/lib/view/page/setting/srv_detail_seq.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/data/res/store.dart'; import '../../../core/extension/order.dart'; @@ -16,14 +16,6 @@ class ServerDetailOrderPage extends StatefulWidget { class _ServerDetailOrderPageState extends State { final Order _cardsOrder = []; - late S _s; - - @override - void didChangeDependencies() { - super.didChangeDependencies(); - _s = S.of(context)!; - } - @override void initState() { super.initState(); @@ -34,7 +26,7 @@ class _ServerDetailOrderPageState extends State { Widget build(BuildContext context) { return Scaffold( appBar: CustomAppBar( - title: Text(_s.serverOrder), + title: Text(l10n.serverOrder), ), body: _buildBody(), ); diff --git a/lib/view/page/setting/srv_seq.dart b/lib/view/page/setting/srv_seq.dart index f64ef7be..9d88627f 100644 --- a/lib/view/page/setting/srv_seq.dart +++ b/lib/view/page/setting/srv_seq.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/order.dart'; import 'package:toolbox/data/res/provider.dart'; import 'package:toolbox/data/res/store.dart'; @@ -15,19 +15,11 @@ class ServerOrderPage extends StatefulWidget { } class _ServerOrderPageState extends State { - late S _s; - - @override - void didChangeDependencies() { - super.didChangeDependencies(); - _s = S.of(context)!; - } - @override Widget build(BuildContext context) { return Scaffold( appBar: CustomAppBar( - title: Text(_s.serverOrder), + title: Text(l10n.serverOrder), ), body: _buildBody(), ); @@ -35,7 +27,7 @@ class _ServerOrderPageState extends State { Widget _buildBody() { if (Providers.server.serverOrder.isEmpty) { - return Center(child: Text(_s.noServerAvailable)); + return Center(child: Text(l10n.noServerAvailable)); } return ReorderableListView.builder( footer: const SizedBox(height: 77), diff --git a/lib/view/page/setting/virt_key.dart b/lib/view/page/setting/virt_key.dart index b821a6a6..27a9b215 100644 --- a/lib/view/page/setting/virt_key.dart +++ b/lib/view/page/setting/virt_key.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/context/snackbar.dart'; import 'package:toolbox/core/extension/order.dart'; import 'package:toolbox/core/utils/platform/base.dart'; @@ -18,19 +18,11 @@ class SSHVirtKeySettingPage extends StatefulWidget { } class _SSHVirtKeySettingPageState extends State { - late S _s; - - @override - void didChangeDependencies() { - super.didChangeDependencies(); - _s = S.of(context)!; - } - @override Widget build(BuildContext context) { return Scaffold( appBar: CustomAppBar( - title: Text(_s.editVirtKeys), + title: Text(l10n.editVirtKeys), ), body: _buildBody(), ); @@ -48,7 +40,7 @@ class _SSHVirtKeySettingPageState extends State { padding: const EdgeInsets.all(7), itemBuilder: (_, idx) { final key = allKeys[idx]; - final help = key.help(_s); + final help = key.help; return RoundRectCard( key: ValueKey(idx), ListTile( @@ -62,7 +54,7 @@ class _SSHVirtKeySettingPageState extends State { itemCount: allKeys.length, onReorder: (o, n) { if (o >= keys.length || n >= keys.length) { - context.showSnackBar(_s.disabled); + context.showSnackBar(l10n.disabled); return; } keys.moveByItem(keys, o, n, property: Stores.setting.sshVirtKeys); diff --git a/lib/view/page/snippet/edit.dart b/lib/view/page/snippet/edit.dart index ffd6aa2f..bea4c985 100644 --- a/lib/view/page/snippet/edit.dart +++ b/lib/view/page/snippet/edit.dart @@ -1,7 +1,7 @@ import 'package:after_layout/after_layout.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:toolbox/core/extension/context/common.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/context/snackbar.dart'; import 'package:toolbox/data/res/provider.dart'; import 'package:toolbox/view/widget/input_field.dart'; @@ -27,8 +27,6 @@ class _SnippetEditPageState extends State final _noteController = TextEditingController(); final _scriptNode = FocusNode(); - late S _s; - List _tags = []; @override @@ -39,17 +37,11 @@ class _SnippetEditPageState extends State _scriptNode.dispose(); } - @override - void didChangeDependencies() { - super.didChangeDependencies(); - _s = S.of(context)!; - } - @override Widget build(BuildContext context) { return Scaffold( appBar: CustomAppBar( - title: Text(_s.edit, style: UIs.textSize18), + title: Text(l10n.edit, style: UIs.textSize18), actions: _buildAppBarActions(), ), body: _buildBody(), @@ -67,7 +59,7 @@ class _SnippetEditPageState extends State Providers.snippet.del(widget.snippet!); context.pop(); }, - tooltip: _s.delete, + tooltip: l10n.delete, icon: const Icon(Icons.delete), ) ]; @@ -81,7 +73,7 @@ class _SnippetEditPageState extends State final name = _nameController.text; final script = _scriptController.text; if (name.isEmpty || script.isEmpty) { - context.showSnackBar(_s.fieldMustNotEmpty); + context.showSnackBar(l10n.fieldMustNotEmpty); return; } final note = _noteController.text; @@ -110,7 +102,7 @@ class _SnippetEditPageState extends State controller: _nameController, type: TextInputType.text, onSubmitted: (_) => FocusScope.of(context).requestFocus(_scriptNode), - label: _s.name, + label: l10n.name, icon: Icons.info, ), Input( @@ -118,7 +110,7 @@ class _SnippetEditPageState extends State minLines: 3, maxLines: 3, type: TextInputType.multiline, - label: _s.note, + label: l10n.note, icon: Icons.note, ), TagEditor( @@ -126,7 +118,6 @@ class _SnippetEditPageState extends State onChanged: (p0) => setState(() { _tags = p0; }), - s: _s, allTags: [...Providers.server.tags], onRenameTag: (old, n) => setState(() { Providers.server.renameTag(old, n); @@ -138,7 +129,7 @@ class _SnippetEditPageState extends State minLines: 3, maxLines: 10, type: TextInputType.multiline, - label: _s.snippet, + label: l10n.snippet, icon: Icons.code, ), ], diff --git a/lib/view/page/snippet/list.dart b/lib/view/page/snippet/list.dart index d0f0721d..685e286d 100644 --- a/lib/view/page/snippet/list.dart +++ b/lib/view/page/snippet/list.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:provider/provider.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/order.dart'; import 'package:toolbox/data/res/provider.dart'; import 'package:toolbox/data/res/store.dart'; @@ -23,7 +23,6 @@ class SnippetListPage extends StatefulWidget { } class _SnippetListPageState extends State { - late S _s; late MediaQueryData _media; String? _tag; @@ -31,7 +30,6 @@ class _SnippetListPageState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - _s = S.of(context)!; _media = MediaQuery.of(context); } @@ -52,7 +50,7 @@ class _SnippetListPageState extends State { builder: (_, provider, __) { if (provider.snippets.isEmpty) { return Center( - child: Text(_s.noSavedSnippet), + child: Text(l10n.noSavedSnippet), ); } @@ -77,7 +75,7 @@ class _SnippetListPageState extends State { tags: provider.tags, onTagChanged: (tag) => setState(() => _tag = tag), initTag: _tag, - all: _s.all, + all: l10n.all, width: _media.size.width, ), footer: UIs.height77, @@ -148,12 +146,12 @@ class _SnippetListPageState extends State { results, ).entries.map((e) => '${e.key}:\n${e.value}').join('\n'); context.showRoundDialog( - title: Text(_s.result), + title: Text(l10n.result), child: Text(result), actions: [ TextButton( onPressed: () => copy2Clipboard(result), - child: Text(_s.copy), + child: Text(l10n.copy), ) ], ); diff --git a/lib/view/page/ssh_term.dart b/lib/view/page/ssh_term.dart index 1d135a4e..7612311c 100644 --- a/lib/view/page/ssh_term.dart +++ b/lib/view/page/ssh_term.dart @@ -5,10 +5,10 @@ import 'package:dartssh2/dartssh2.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:provider/provider.dart'; import 'package:toolbox/core/extension/context/common.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/context/snackbar.dart'; import 'package:toolbox/core/utils/platform/base.dart'; import 'package:toolbox/data/res/store.dart'; @@ -43,7 +43,6 @@ class _SSHPageState extends State { final List> _virtKeysList = []; late MediaQueryData _media; - late S _s; late TerminalStyle _terminalStyle; late TerminalTheme _terminalTheme; late TextInputType _keyboardType; @@ -88,7 +87,6 @@ class _SSHPageState extends State { super.didChangeDependencies(); _isDark = context.isDark; _media = MediaQuery.of(context); - _s = S.of(context)!; _terminalTheme = _isDark ? TerminalThemes.dark : TerminalThemes.light; // Because the virtual keyboard only displayed on mobile devices @@ -252,7 +250,7 @@ class _SSHPageState extends State { } break; case VirtualKeyFunc.snippet: - context.showSnippetDialog(_s, (s) { + context.showSnippetDialog((s) { _terminal.textInput(s.script); _terminal.keyInput(TerminalKey.enter); }); @@ -269,7 +267,7 @@ class _SSHPageState extends State { final initPath = cmds[idx + 1].toString(); if (initPath.isEmpty || !initPath.startsWith('/')) { context.showRoundDialog( - title: Text(_s.error), + title: Text(l10n.error), child: const Text('Failed to get current path'), ); return; @@ -401,8 +399,8 @@ class _SSHPageState extends State { if (!mounted) return; _write('\n\nConnection lost\r\n'); context.showRoundDialog( - title: Text(_s.attention), - child: Text('${_s.disconnected}\n${_s.goBackQ}'), + title: Text(l10n.attention), + child: Text('${l10n.disconnected}\n${l10n.goBackQ}'), barrierDismiss: false, actions: [ TextButton( @@ -412,7 +410,7 @@ class _SSHPageState extends State { context.pop(); } }, - child: Text(_s.ok), + child: Text(l10n.ok), ), ], ); diff --git a/lib/view/page/storage/local.dart b/lib/view/page/storage/local.dart index 72f159f9..6c7e3958 100644 --- a/lib/view/page/storage/local.dart +++ b/lib/view/page/storage/local.dart @@ -1,9 +1,9 @@ import 'dart:io'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:toolbox/core/extension/context/common.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/context/snackbar.dart'; import 'package:toolbox/data/model/sftp/req.dart'; import 'package:toolbox/data/res/misc.dart'; @@ -37,7 +37,6 @@ class LocalStoragePage extends StatefulWidget { class _LocalStoragePageState extends State { LocalPath? _path; - late S _s; @override void initState() { @@ -55,12 +54,6 @@ class _LocalStoragePageState extends State { } } - @override - void didChangeDependencies() { - super.didChangeDependencies(); - _s = S.of(context)!; - } - @override Widget build(BuildContext context) { return Scaffold( @@ -74,7 +67,7 @@ class _LocalStoragePageState extends State { context.pop(); }, ), - title: Text(_s.files), + title: Text(l10n.files), actions: [ IconButton( icon: const Icon(Icons.downloading), @@ -96,7 +89,7 @@ class _LocalStoragePageState extends State { child: Column( mainAxisSize: MainAxisSize.min, children: [ - (_path?.path ?? _s.loadingFiles).omitStartStr(), + (_path?.path ?? l10n.loadingFiles).omitStartStr(), _buildBtns(), ], ), @@ -200,7 +193,7 @@ class _LocalStoragePageState extends State { context.pop(); _showRenameDialog(file); }, - title: Text(_s.rename), + title: Text(l10n.rename), leading: const Icon(Icons.abc), ), ListTile( @@ -208,7 +201,7 @@ class _LocalStoragePageState extends State { context.pop(); _showDeleteDialog(file); }, - title: Text(_s.delete), + title: Text(l10n.delete), leading: const Icon(Icons.delete), ), ], @@ -220,7 +213,7 @@ class _LocalStoragePageState extends State { final fileName = file.path.split('/').last; if (widget.isPickFile) { await context.showRoundDialog( - title: Text(_s.pickFile), + title: Text(l10n.pickFile), child: Text(fileName), actions: [ TextButton( @@ -228,7 +221,7 @@ class _LocalStoragePageState extends State { context.pop(); context.pop(file.path); }, - child: Text(_s.ok), + child: Text(l10n.ok), ), ]); return; @@ -239,14 +232,14 @@ class _LocalStoragePageState extends State { children: [ ListTile( leading: const Icon(Icons.edit), - title: Text(_s.edit), + title: Text(l10n.edit), onTap: () async { context.pop(); final stat = await file.stat(); if (stat.size > Miscs.editorMaxSize) { context.showRoundDialog( - title: Text(_s.attention), - child: Text(_s.fileTooLarge(fileName, stat.size, '1m')), + title: Text(l10n.attention), + child: Text(l10n.fileTooLarge(fileName, stat.size, '1m')), ); return; } @@ -256,14 +249,14 @@ class _LocalStoragePageState extends State { final f = File(file.absolute.path); if (result != null) { f.writeAsString(result); - context.showSnackBar(_s.saved); + context.showSnackBar(l10n.saved); setState(() {}); } }, ), ListTile( leading: const Icon(Icons.abc), - title: Text(_s.rename), + title: Text(l10n.rename), onTap: () { context.pop(); _showRenameDialog(file); @@ -271,7 +264,7 @@ class _LocalStoragePageState extends State { ), ListTile( leading: const Icon(Icons.delete), - title: Text(_s.delete), + title: Text(l10n.delete), onTap: () { context.pop(); _showDeleteDialog(file); @@ -279,20 +272,20 @@ class _LocalStoragePageState extends State { ), ListTile( leading: const Icon(Icons.upload), - title: Text(_s.upload), + title: Text(l10n.upload), onTap: () async { context.pop(); final ids = Providers.server.serverOrder; var idx = 0; await context.showRoundDialog( - title: Text(_s.server), + title: Text(l10n.server), child: Picker( items: ids.map((e) => Text(e)).toList(), onSelected: (idx_) => idx = idx_, ), actions: [ TextButton( - onPressed: () => context.pop(), child: Text(_s.ok)), + onPressed: () => context.pop(), child: Text(l10n.ok)), ], ); final id = ids[idx]; @@ -313,12 +306,12 @@ class _LocalStoragePageState extends State { file.absolute.path, SftpReqType.upload, )); - context.showSnackBar(_s.added2List); + context.showSnackBar(l10n.added2List); }, ), ListTile( leading: const Icon(Icons.open_in_new), - title: Text(_s.open), + title: Text(l10n.open), onTap: () { shareFiles(context, [file.absolute.path]); }, @@ -331,7 +324,7 @@ class _LocalStoragePageState extends State { void _showRenameDialog(FileSystemEntity file) { final fileName = file.path.split('/').last; context.showRoundDialog( - title: Text(_s.rename), + title: Text(l10n.rename), child: Input( autoFocus: true, controller: TextEditingController(text: fileName), @@ -341,7 +334,7 @@ class _LocalStoragePageState extends State { try { file.renameSync(newPath); } catch (e) { - context.showSnackBar('${_s.failed}:\n$e'); + context.showSnackBar('${l10n.failed}:\n$e'); return; } @@ -354,12 +347,12 @@ class _LocalStoragePageState extends State { void _showDeleteDialog(FileSystemEntity file) { final fileName = file.path.split('/').last; context.showRoundDialog( - title: Text(_s.delete), - child: Text(_s.sureDelete(fileName)), + title: Text(l10n.delete), + child: Text(l10n.sureDelete(fileName)), actions: [ TextButton( onPressed: () => context.pop(), - child: Text(_s.cancel), + child: Text(l10n.cancel), ), TextButton( onPressed: () { @@ -367,12 +360,12 @@ class _LocalStoragePageState extends State { try { file.deleteSync(recursive: true); } catch (e) { - context.showSnackBar('${_s.failed}:\n$e'); + context.showSnackBar('${l10n.failed}:\n$e'); return; } setState(() {}); }, - child: Text(_s.ok), + child: Text(l10n.ok), ), ], ); diff --git a/lib/view/page/storage/sftp.dart b/lib/view/page/storage/sftp.dart index 8460a0fd..a6e06128 100644 --- a/lib/view/page/storage/sftp.dart +++ b/lib/view/page/storage/sftp.dart @@ -3,9 +3,9 @@ import 'dart:async'; import 'package:after_layout/after_layout.dart'; import 'package:dartssh2/dartssh2.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:toolbox/core/extension/context/common.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/context/snackbar.dart'; import 'package:toolbox/core/extension/sftpfile.dart'; import 'package:toolbox/core/utils/platform/base.dart'; @@ -49,14 +49,11 @@ class SftpPage extends StatefulWidget { class _SftpPageState extends State with AfterLayoutMixin { final SftpBrowserStatus _status = SftpBrowserStatus(); - late S _s; - SSHClient? _client; @override void didChangeDependencies() { super.didChangeDependencies(); - _s = S.of(context)!; } @override @@ -130,7 +127,7 @@ class _SftpPageState extends State with AfterLayoutMixin { child: Column( mainAxisSize: MainAxisSize.min, children: [ - (_status.path?.path ?? _s.loadingFiles).omitStartStr(), + (_status.path?.path ?? l10n.loadingFiles).omitStartStr(), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: children, @@ -150,12 +147,12 @@ class _SftpPageState extends State with AfterLayoutMixin { children: [ ListTile( leading: const Icon(Icons.open_in_new), - title: Text(_s.system), + title: Text(l10n.system), onTap: () => context.pop(1), ), ListTile( leading: const Icon(Icons.folder), - title: Text(_s.inner), + title: Text(l10n.inner), onTap: () => context.pop(0), ), ], @@ -199,11 +196,11 @@ class _SftpPageState extends State with AfterLayoutMixin { children: [ ListTile( leading: const Icon(Icons.folder), - title: Text(_s.createFolder), + title: Text(l10n.createFolder), onTap: () => _mkdir(context)), ListTile( leading: const Icon(Icons.insert_drive_file), - title: Text(_s.createFile), + title: Text(l10n.createFile), onTap: () => _newFile(context)), ], ), @@ -217,7 +214,7 @@ class _SftpPageState extends State with AfterLayoutMixin { padding: const EdgeInsets.all(0), onPressed: () async { final p = await context.showRoundDialog( - title: Text(_s.goto), + title: Text(l10n.goto), child: Autocomplete( optionsBuilder: (val) { if (!Stores.setting.recordHistory.fetch()) { @@ -231,7 +228,7 @@ class _SftpPageState extends State with AfterLayoutMixin { return Input( autoFocus: true, icon: Icons.abc, - label: _s.path, + label: l10n.path, node: node, controller: controller, onSubmitted: (value) => context.pop(value), @@ -318,12 +315,12 @@ class _SftpPageState extends State with AfterLayoutMixin { final children = [ ListTile( leading: const Icon(Icons.delete), - title: Text(_s.delete), + title: Text(l10n.delete), onTap: () => _delete(context, file), ), ListTile( leading: const Icon(Icons.abc), - title: Text(_s.rename), + title: Text(l10n.rename), onTap: () => _rename(context, file), ), ]; @@ -331,19 +328,19 @@ class _SftpPageState extends State with AfterLayoutMixin { children.addAll([ ListTile( leading: const Icon(Icons.edit), - title: Text(_s.edit), + title: Text(l10n.edit), onTap: () => _edit(context, file), ), ListTile( leading: const Icon(Icons.download), - title: Text(_s.download), + title: Text(l10n.download), onTap: () => _download(context, file), ), // Only show decompress option when the file is a compressed file if (_canDecompress(file.filename)) ListTile( leading: const Icon(Icons.folder_zip), - title: Text(_s.decompress), + title: Text(l10n.decompress), onTap: () => _decompress(context, file), ), ]); @@ -359,7 +356,7 @@ class _SftpPageState extends State with AfterLayoutMixin { Future _edit(BuildContext context, SftpName name) async { final size = name.attr.size; if (size == null || size > Miscs.editorMaxSize) { - context.showSnackBar(_s.fileTooLarge( + context.showSnackBar(l10n.fileTooLarge( name.filename, size ?? 0, Miscs.editorMaxSize, @@ -386,18 +383,18 @@ class _SftpPageState extends State with AfterLayoutMixin { if (result != null && result) { Providers.sftp .add(SftpReq(req.spi, remotePath, localPath, SftpReqType.upload)); - context.showSnackBar(_s.added2List); + context.showSnackBar(l10n.added2List); } } void _download(BuildContext context, SftpName name) { context.showRoundDialog( - title: Text(_s.attention), - child: Text('${_s.dl2Local(name.filename)}\n${_s.keepForeground}'), + title: Text(l10n.attention), + child: Text('${l10n.dl2Local(name.filename)}\n${l10n.keepForeground}'), actions: [ TextButton( onPressed: () => context.pop(), - child: Text(_s.cancel), + child: Text(l10n.cancel), ), TextButton( onPressed: () async { @@ -415,7 +412,7 @@ class _SftpPageState extends State with AfterLayoutMixin { context.pop(); }, - child: Text(_s.download), + child: Text(l10n.download), ) ], ); @@ -425,16 +422,16 @@ class _SftpPageState extends State with AfterLayoutMixin { context.pop(); final isDir = file.attr.isDirectory; final useRmrf = Stores.setting.sftpRmrfDir.fetch(); - final dirText = (isDir && !useRmrf) ? '\n${_s.sureDirEmpty}' : ''; - final text = '${_s.sureDelete(file.filename)}$dirText'; + final dirText = (isDir && !useRmrf) ? '\n${l10n.sureDirEmpty}' : ''; + final text = '${l10n.sureDelete(file.filename)}$dirText'; final child = Text(text); context.showRoundDialog( child: child, - title: Text(_s.attention), + title: Text(l10n.attention), actions: [ TextButton( onPressed: () => context.pop(), - child: Text(_s.cancel), + child: Text(l10n.cancel), ), TextButton( onPressed: () async { @@ -453,12 +450,12 @@ class _SftpPageState extends State with AfterLayoutMixin { } catch (e) { context.pop(); context.showRoundDialog( - title: Text(_s.error), + title: Text(l10n.error), child: Text(e.toString()), actions: [ TextButton( onPressed: () => context.pop(), - child: Text(_s.ok), + child: Text(l10n.ok), ) ], ); @@ -466,7 +463,7 @@ class _SftpPageState extends State with AfterLayoutMixin { } _listDir(); }, - child: Text(_s.delete, style: UIs.textRed), + child: Text(l10n.delete, style: UIs.textRed), ), ], ); @@ -476,27 +473,27 @@ class _SftpPageState extends State with AfterLayoutMixin { context.pop(); final textController = TextEditingController(); context.showRoundDialog( - title: Text(_s.createFolder), + title: Text(l10n.createFolder), child: Input( autoFocus: true, icon: Icons.folder, controller: textController, - label: _s.name, + label: l10n.name, ), actions: [ TextButton( onPressed: () => context.pop(), - child: Text(_s.cancel), + child: Text(l10n.cancel), ), TextButton( onPressed: () async { if (textController.text == '') { context.showRoundDialog( - child: Text(_s.fieldMustNotEmpty), + child: Text(l10n.fieldMustNotEmpty), actions: [ TextButton( onPressed: () => context.pop(), - child: Text(_s.ok), + child: Text(l10n.ok), ), ], ); @@ -507,7 +504,7 @@ class _SftpPageState extends State with AfterLayoutMixin { context.pop(); _listDir(); }, - child: Text(_s.ok, style: UIs.textRed), + child: Text(l10n.ok, style: UIs.textRed), ), ], ); @@ -517,24 +514,24 @@ class _SftpPageState extends State with AfterLayoutMixin { context.pop(); final textController = TextEditingController(); context.showRoundDialog( - title: Text(_s.createFile), + title: Text(l10n.createFile), child: Input( autoFocus: true, icon: Icons.insert_drive_file, controller: textController, - label: _s.name, + label: l10n.name, ), actions: [ TextButton( onPressed: () async { if (textController.text == '') { context.showRoundDialog( - title: Text(_s.attention), - child: Text(_s.fieldMustNotEmpty), + title: Text(l10n.attention), + child: Text(l10n.fieldMustNotEmpty), actions: [ TextButton( onPressed: () => context.pop(), - child: Text(_s.ok), + child: Text(l10n.ok), ), ], ); @@ -547,7 +544,7 @@ class _SftpPageState extends State with AfterLayoutMixin { context.pop(); _listDir(); }, - child: Text(_s.ok, style: UIs.textRed), + child: Text(l10n.ok, style: UIs.textRed), ), ], ); @@ -557,25 +554,25 @@ class _SftpPageState extends State with AfterLayoutMixin { context.pop(); final textController = TextEditingController(); context.showRoundDialog( - title: Text(_s.rename), + title: Text(l10n.rename), child: Input( autoFocus: true, icon: Icons.abc, controller: textController, - label: _s.name, + label: l10n.name, ), actions: [ - TextButton(onPressed: () => context.pop(), child: Text(_s.cancel)), + TextButton(onPressed: () => context.pop(), child: Text(l10n.cancel)), TextButton( onPressed: () async { if (textController.text == '') { context.showRoundDialog( - title: Text(_s.attention), - child: Text(_s.fieldMustNotEmpty), + title: Text(l10n.attention), + child: Text(l10n.fieldMustNotEmpty), actions: [ TextButton( onPressed: () => context.pop(), - child: Text(_s.ok), + child: Text(l10n.ok), ), ], ); @@ -585,7 +582,7 @@ class _SftpPageState extends State with AfterLayoutMixin { context.pop(); _listDir(); }, - child: Text(_s.rename, style: UIs.textRed), + child: Text(l10n.rename, style: UIs.textRed), ), ], ); @@ -597,12 +594,12 @@ class _SftpPageState extends State with AfterLayoutMixin { final cmd = _getDecompressCmd(absPath); if (cmd == null) { context.showRoundDialog( - title: Text(_s.error), + title: Text(l10n.error), child: Text('Unsupport file: ${name.filename}'), actions: [ TextButton( onPressed: () => context.pop(), - child: Text(_s.ok), + child: Text(l10n.ok), ), ], ); @@ -664,12 +661,12 @@ class _SftpPageState extends State with AfterLayoutMixin { Future.delayed( const Duration(milliseconds: 177), () => context.showRoundDialog( - title: Text(_s.error), + title: Text(l10n.error), child: Text(e.toString()), actions: [ TextButton( onPressed: () => context.pop(), - child: Text(_s.ok), + child: Text(l10n.ok), ) ], ), diff --git a/lib/view/page/storage/sftp_mission.dart b/lib/view/page/storage/sftp_mission.dart index 761b800e..aa01a42c 100644 --- a/lib/view/page/storage/sftp_mission.dart +++ b/lib/view/page/storage/sftp_mission.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:provider/provider.dart'; import 'package:toolbox/core/extension/context/common.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/datetime.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; import 'package:toolbox/core/route.dart'; @@ -23,19 +23,11 @@ class SftpMissionPage extends StatefulWidget { } class _SftpMissionPageState extends State { - late S _s; - - @override - void didChangeDependencies() { - super.didChangeDependencies(); - _s = S.of(context)!; - } - @override Widget build(BuildContext context) { return Scaffold( appBar: CustomAppBar( - title: Text(_s.mission, style: UIs.textSize18), + title: Text(l10n.mission, style: UIs.textSize18), ), body: _buildBody(), ); @@ -45,7 +37,7 @@ class _SftpMissionPageState extends State { return Consumer(builder: (__, pro, _) { if (pro.status.isEmpty) { return Center( - child: Text(_s.noTask), + child: Text(l10n.noTask), ); } return ListView.builder( @@ -63,8 +55,8 @@ class _SftpMissionPageState extends State { switch (status.status) { case SftpWorkerStatus.finished: final time = status.spentTime.toString(); - final str = '${_s.finished} ${_s.spentTime( - time == 'null' ? _s.unknown : (time.substring(0, time.length - 7)), + final str = '${l10n.finished} ${l10n.spentTime( + time == 'null' ? l10n.unknown : (time.substring(0, time.length - 7)), )}'; return _wrapInCard( status: status, @@ -91,29 +83,29 @@ class _SftpMissionPageState extends State { final size = (status.size ?? 0).convertBytes; return _wrapInCard( status: status, - subtitle: _s.percentOfSize(percentStr, size), + subtitle: l10n.percentOfSize(percentStr, size), trailing: _buildDelete(status.fileName, status.id), ); case SftpWorkerStatus.preparing: return _wrapInCard( status: status, - subtitle: _s.sftpDlPrepare, + subtitle: l10n.sftpDlPrepare, trailing: _buildDelete(status.fileName, status.id), ); case SftpWorkerStatus.sshConnectted: return _wrapInCard( status: status, - subtitle: _s.sftpSSHConnected, + subtitle: l10n.sftpSSHConnected, trailing: _buildDelete(status.fileName, status.id), ); default: return _wrapInCard( status: status, - subtitle: _s.unknown, + subtitle: l10n.unknown, trailing: IconButton( onPressed: () => context.showRoundDialog( - title: Text(_s.error), - child: Text((status.error ?? _s.unknown).toString()), + title: Text(l10n.error), + child: Text((status.error ?? l10n.unknown).toString()), ), icon: const Icon(Icons.error), ), @@ -144,15 +136,15 @@ class _SftpMissionPageState extends State { Widget _buildDelete(String name, int id) { return IconButton( onPressed: () => context.showRoundDialog( - title: Text(_s.attention), - child: Text(_s.sureDelete(name)), + title: Text(l10n.attention), + child: Text(l10n.sureDelete(name)), actions: [ TextButton( onPressed: () { Providers.sftp.cancel(id); context.pop(); }, - child: Text(_s.ok), + child: Text(l10n.ok), ), ]), icon: const Icon(Icons.delete), diff --git a/lib/view/widget/server_func_btns.dart b/lib/view/widget/server_func_btns.dart index 81e6cfc9..ada5bf03 100644 --- a/lib/view/widget/server_func_btns.dart +++ b/lib/view/widget/server_func_btns.dart @@ -1,9 +1,9 @@ import 'dart:io'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:toolbox/core/extension/context/common.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/extension/context/snackbar.dart'; import 'package:toolbox/core/extension/ssh_client.dart'; import 'package:toolbox/core/extension/uint8list.dart'; @@ -25,12 +25,10 @@ import 'tag.dart'; class ServerFuncBtnsTopRight extends StatelessWidget { final ServerPrivateInfo spi; - final S s; const ServerFuncBtnsTopRight({ super.key, required this.spi, - required this.s, }); @override @@ -45,13 +43,13 @@ class ServerFuncBtnsTopRight extends StatelessWidget { const SizedBox( width: 10, ), - Text(e.text(s)), + Text(e.toStr), ], ), )) .toList(), padding: const EdgeInsets.symmetric(horizontal: 10), - onSelected: (val) => _onTapMoreBtns(val, spi, context, s), + onSelected: (val) => _onTapMoreBtns(val, spi, context), ); } } @@ -60,12 +58,10 @@ class ServerFuncBtns extends StatelessWidget { const ServerFuncBtns({ super.key, required this.spi, - required this.s, this.iconSize, }); final ServerPrivateInfo spi; - final S s; final double? iconSize; @override @@ -74,7 +70,7 @@ class ServerFuncBtns extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceAround, children: ServerTabMenuType.values .map((e) => IconButton( - onPressed: () => _onTapMoreBtns(e, spi, context, s), + onPressed: () => _onTapMoreBtns(e, spi, context), padding: EdgeInsets.zero, tooltip: e.name, icon: Icon(e.icon, size: iconSize ?? 15), @@ -88,16 +84,15 @@ void _onTapMoreBtns( ServerTabMenuType value, ServerPrivateInfo spi, BuildContext context, - S s, ) async { switch (value) { case ServerTabMenuType.pkg: - _onPkg(context, s, spi); + _onPkg(context, spi); break; case ServerTabMenuType.sftp: AppRoute.sftp(spi: spi).checkGo( context: context, - check: () => _checkClient(context, spi.id, s.waitConnection), + check: () => _checkClient(context, spi.id), ); break; case ServerTabMenuType.snippet: @@ -114,12 +109,12 @@ void _onTapMoreBtns( final result = await Providers.server.runSnippets(spi.id, snippets); if (result != null && result.isNotEmpty) { context.showRoundDialog( - title: Text(s.result), + title: Text(l10n.result), child: Text(result), actions: [ TextButton( onPressed: () => copy2Clipboard(result), - child: Text(s.copy), + child: Text(l10n.copy), ) ], ); @@ -128,13 +123,13 @@ void _onTapMoreBtns( case ServerTabMenuType.docker: AppRoute.docker(spi: spi).checkGo( context: context, - check: () => _checkClient(context, spi.id, s.waitConnection), + check: () => _checkClient(context, spi.id), ); break; case ServerTabMenuType.process: AppRoute.process(spi: spi).checkGo( context: context, - check: () => _checkClient(context, spi.id, s.waitConnection), + check: () => _checkClient(context, spi.id), ); break; case ServerTabMenuType.terminal: @@ -192,19 +187,19 @@ Future _gotoSSH( } } -bool _checkClient(BuildContext context, String id, String msg) { +bool _checkClient(BuildContext context, String id) { final server = Providers.server.servers[id]; if (server == null || server.client == null) { - context.showSnackBar(msg); + context.showSnackBar(l10n.waitConnection); return false; } return true; } -Future _onPkg(BuildContext context, S s, ServerPrivateInfo spi) async { +Future _onPkg(BuildContext context, ServerPrivateInfo spi) async { final server = spi.findServer; if (server == null) { - context.showSnackBar(s.noClient); + context.showSnackBar(l10n.noClient); return; } final sys = server.status.sysVer; @@ -232,13 +227,13 @@ Future _onPkg(BuildContext context, S s, ServerPrivateInfo spi) async { final result = await server.client?.run(listCmd).string; context.pop(); if (result == null) { - context.showSnackBar(s.noResult); + context.showSnackBar(l10n.noResult); return; } final list = pkg?.updateListRemoveUnused(result.split('\n')); final upgradeable = list?.map((e) => UpgradePkgInfo(e, pkg)).toList(); if (upgradeable == null || upgradeable.isEmpty) { - context.showSnackBar(s.noUpdateAvailable); + context.showSnackBar(l10n.noUpdateAvailable); return; } final args = upgradeable.map((e) => e.package).join(' '); @@ -247,14 +242,14 @@ Future _onPkg(BuildContext context, S s, ServerPrivateInfo spi) async { // Confirm upgrade final gotoUpgrade = await context.showRoundDialog( - title: Text(s.attention), + title: Text(l10n.attention), child: SingleChildScrollView( - child: Text('${s.foundNUpdate(upgradeable.length)}\n\n$upgradeCmd'), + child: Text('${l10n.foundNUpdate(upgradeable.length)}\n\n$upgradeCmd'), ), actions: [ TextButton( onPressed: () => context.pop(true), - child: Text(s.update), + child: Text(l10n.update), ), ], ); @@ -263,6 +258,6 @@ Future _onPkg(BuildContext context, S s, ServerPrivateInfo spi) async { AppRoute.ssh(spi: spi, initCmd: upgradeCmd).checkGo( context: context, - check: () => _checkClient(context, spi.id, s.waitConnection), + check: () => _checkClient(context, spi.id), ); } diff --git a/lib/view/widget/tag.dart b/lib/view/widget/tag.dart index 1f8e8540..fd043aa4 100644 --- a/lib/view/widget/tag.dart +++ b/lib/view/widget/tag.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:toolbox/core/extension/context/common.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; +import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/data/res/ui.dart'; import 'package:toolbox/view/widget/input_field.dart'; import 'package:toolbox/view/widget/round_rect_card.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import '../../data/model/app/tag_pickable.dart'; import '../../data/res/color.dart'; @@ -39,7 +39,6 @@ class TagBtn extends StatelessWidget { class TagEditor extends StatefulWidget { final List tags; - final S s; final void Function(List)? onChanged; final void Function(String old, String new_)? onRenameTag; final List allTags; @@ -47,7 +46,6 @@ class TagEditor extends StatefulWidget { const TagEditor({ super.key, required this.tags, - required this.s, this.onChanged, this.onRenameTag, this.allTags = const [], @@ -78,7 +76,7 @@ class _TagEditorState extends State { /// Add vertical divider if suggestions.length > 0 final counts = tags.length + suggestionLen + (suggestionLen == 0 ? 0 : 1); - if (counts == 0) return Text(widget.s.tag); + if (counts == 0) return Text(l10n.tag); return ConstrainedBox( constraints: const BoxConstraints(maxHeight: _kTagBtnHeight), child: ListView.builder( @@ -134,12 +132,12 @@ class _TagEditorState extends State { void _showAddTagDialog() { final textEditingController = TextEditingController(); context.showRoundDialog( - title: Text(widget.s.add), + title: Text(l10n.add), child: Input( autoFocus: true, icon: Icons.tag, controller: textEditingController, - hint: widget.s.tag, + hint: l10n.tag, ), actions: [ TextButton( @@ -149,7 +147,7 @@ class _TagEditorState extends State { widget.onChanged?.call(widget.tags); context.pop(); }, - child: Text(widget.s.add), + child: Text(l10n.add), ), ], ); @@ -158,12 +156,12 @@ class _TagEditorState extends State { void _showRenameDialog(String tag) { final textEditingController = TextEditingController(text: tag); context.showRoundDialog( - title: Text(widget.s.rename), + title: Text(l10n.rename), child: Input( autoFocus: true, icon: Icons.abc, controller: textEditingController, - hint: widget.s.tag, + hint: l10n.tag, ), actions: [ TextButton( @@ -174,7 +172,7 @@ class _TagEditorState extends State { context.pop(); setState(() {}); }, - child: Text(widget.s.rename), + child: Text(l10n.rename), ), ], ); @@ -196,14 +194,12 @@ class TagPicker extends StatefulWidget { } class _TagPickerState extends State> { - late S _s; late MediaQueryData _media; final List _selected = []; @override void didChangeDependencies() { super.didChangeDependencies(); - _s = S.of(context)!; _media = MediaQuery.of(context); } @@ -211,7 +207,7 @@ class _TagPickerState extends State> { Widget build(BuildContext context) { final children = []; if (widget.tags.isNotEmpty) { - children.add(Text(_s.tag)); + children.add(Text(l10n.tag)); children.add(UIs.height13); children.add(SizedBox( height: _kTagBtnHeight, @@ -220,7 +216,7 @@ class _TagPickerState extends State> { )); } if (widget.items.isNotEmpty) { - children.add(Text(_s.all)); + children.add(Text(l10n.all)); children.add(UIs.height13); children.add(SizedBox( height: _kTagBtnHeight, @@ -229,15 +225,15 @@ class _TagPickerState extends State> { )); } final child = widget.tags.isEmpty && widget.items.isEmpty - ? Text(_s.noOptions) + ? Text(l10n.noOptions) : Column(mainAxisSize: MainAxisSize.min, children: children); return AlertDialog( - title: Text(_s.choose), + title: Text(l10n.choose), content: child, actions: [ TextButton( onPressed: () => context.pop(_selected), - child: Text(_s.ok), + child: Text(l10n.ok), ), ], );