diff --git a/lib/core/route.dart b/lib/core/route.dart index 6324a87b..37e5d490 100644 --- a/lib/core/route.dart +++ b/lib/core/route.dart @@ -110,8 +110,15 @@ class AppRoute { return AppRoute(SSHVirtKeySettingPage(key: key), 'ssh_virt_key_setting'); } - static AppRoute localStorage({Key? key}) { - return AppRoute(LocalStoragePage(key: key), 'local_storage'); + static AppRoute localStorage( + {Key? key, bool isPickFile = false, String? initDir}) { + return AppRoute( + LocalStoragePage( + key: key, + isPickFile: isPickFile, + initDir: initDir, + ), + 'local_storage'); } static AppRoute sftpMission({Key? key}) { diff --git a/lib/core/utils/ui.dart b/lib/core/utils/ui.dart index c7887202..2a924552 100644 --- a/lib/core/utils/ui.dart +++ b/lib/core/utils/ui.dart @@ -11,7 +11,6 @@ import '../../data/model/server/snippet.dart'; import '../../data/provider/snippet.dart'; import '../../data/res/ui.dart'; import '../../locator.dart'; -import '../../view/page/snippet/edit.dart'; import '../../view/widget/picker.dart'; import '../persistant_store.dart'; import '../route.dart'; @@ -146,7 +145,7 @@ void showSnippetDialog( TextButton( onPressed: () { context.pop(); - AppRoute(const SnippetEditPage(), 'edit snippet').go(context); + AppRoute.snippetEdit().go(context); }, child: Text(s.add), ) diff --git a/lib/view/page/docker.dart b/lib/view/page/docker.dart index 25f9cd7e..2ccdfdcf 100644 --- a/lib/view/page/docker.dart +++ b/lib/view/page/docker.dart @@ -4,7 +4,6 @@ import 'package:provider/provider.dart'; import 'package:toolbox/core/extension/navigator.dart'; import 'package:toolbox/core/route.dart'; import 'package:toolbox/data/model/docker/image.dart'; -import 'package:toolbox/view/page/ssh_term.dart'; import 'package:toolbox/view/widget/input_field.dart'; import '../../core/utils/ui.dart'; @@ -457,21 +456,15 @@ class _DockerManagePageState extends State { context.pop(); break; case DockerMenuType.logs: - AppRoute( - SSHPage( - spi: widget.spi, - initCmd: 'docker logs -f --tail 100 ${dItem.containerId}', - ), - 'Docker logs', + AppRoute.ssh( + spi: widget.spi, + initCmd: 'docker logs -f --tail 100 ${dItem.containerId}', ).go(context); break; case DockerMenuType.terminal: - AppRoute( - SSHPage( - spi: widget.spi, - initCmd: 'docker exec -it ${dItem.containerId} sh', - ), - 'Docker terminal', + AppRoute.ssh( + spi: widget.spi, + initCmd: 'docker exec -it ${dItem.containerId} sh', ).go(context); break; // case DockerMenuType.stats: diff --git a/lib/view/page/full_screen.dart b/lib/view/page/full_screen.dart index c5113966..b76c64c8 100644 --- a/lib/view/page/full_screen.dart +++ b/lib/view/page/full_screen.dart @@ -22,8 +22,6 @@ import '../../data/model/server/server.dart'; import '../../data/model/server/server_private_info.dart'; import '../../data/model/server/server_status.dart'; import '../../data/res/color.dart'; -import 'server/edit.dart'; -import 'setting/entry.dart'; class FullScreenPage extends StatefulWidget { const FullScreenPage({Key? key}) : super(key: key); @@ -117,10 +115,7 @@ class _FullScreenPageState extends State with AfterLayoutMixin { Widget _buildSettingBtn() { return IconButton( - onPressed: () => AppRoute( - const SettingPage(), - 'Setting', - ).go(context), + onPressed: () => AppRoute.setting().go(context), icon: const Icon(Icons.settings, color: Colors.grey)); } @@ -129,10 +124,7 @@ class _FullScreenPageState extends State with AfterLayoutMixin { if (pro.serverOrder.isEmpty) { return Center( child: TextButton( - onPressed: () => AppRoute( - const ServerEditPage(), - 'Add server info page', - ).go(context), + onPressed: () => AppRoute.serverEdit().go(context), child: Text( _s.addAServer, style: const TextStyle(fontSize: 27), diff --git a/lib/view/page/home.dart b/lib/view/page/home.dart index 12304deb..d2b6a667 100644 --- a/lib/view/page/home.dart +++ b/lib/view/page/home.dart @@ -22,12 +22,6 @@ import '../../data/store/setting.dart'; import '../../locator.dart'; import '../widget/custom_appbar.dart'; import '../widget/url_text.dart'; -import 'backup.dart'; -import 'convert.dart'; -import 'debug.dart'; -import 'private_key/list.dart'; -import 'setting/entry.dart'; -import 'storage/local.dart'; class HomePage extends StatefulWidget { const HomePage({Key? key}) : super(key: key); @@ -136,10 +130,7 @@ class _HomePageState extends State IconButton( icon: const Icon(Icons.developer_mode, size: 23), tooltip: _s.debug, - onPressed: () => AppRoute( - const DebugPage(), - 'Debug Page', - ).go(context), + onPressed: () => AppRoute.debug().go(context), ), ]; if (isDesktop && _selectIndex.value == AppTab.server.index) { @@ -238,42 +229,27 @@ class _HomePageState extends State ListTile( leading: const Icon(Icons.settings), title: Text(_s.setting), - onTap: () => AppRoute( - const SettingPage(), - 'Setting', - ).go(context), + onTap: () => AppRoute.setting().go(context), ), ListTile( leading: const Icon(Icons.vpn_key), title: Text(_s.privateKey), - onTap: () => AppRoute( - const PrivateKeysListPage(), - 'private key list', - ).go(context), + onTap: () => AppRoute.keyList().go(context), ), ListTile( leading: const Icon(Icons.download), title: Text(_s.download), - onTap: () => AppRoute( - const LocalStoragePage(), - 'sftp local page', - ).go(context), + onTap: () => AppRoute.localStorage().go(context), ), ListTile( leading: const Icon(Icons.import_export), title: Text(_s.backup), - onTap: () => AppRoute( - BackupPage(), - 'backup page', - ).go(context), + onTap: () => AppRoute.backup().go(context), ), ListTile( leading: const Icon(Icons.code), title: Text(_s.convert), - onTap: () => AppRoute( - const ConvertPage(), - 'convert page', - ).go(context), + onTap: () => AppRoute.convert().go(context), ), ListTile( leading: const Icon(Icons.text_snippet), diff --git a/lib/view/page/private_key/list.dart b/lib/view/page/private_key/list.dart index 669c7c1d..8ef2c045 100644 --- a/lib/view/page/private_key/list.dart +++ b/lib/view/page/private_key/list.dart @@ -15,7 +15,6 @@ import '../../../data/model/server/private_key_info.dart'; import '../../../data/provider/private_key.dart'; import '../../../data/res/ui.dart'; import '../../widget/custom_appbar.dart'; -import 'edit.dart'; import '../../../view/widget/round_rect_card.dart'; class PrivateKeysListPage extends StatefulWidget { @@ -44,10 +43,7 @@ class _PrivateKeyListState extends State body: _buildBody(), floatingActionButton: FloatingActionButton( child: const Icon(Icons.add), - onPressed: () => AppRoute( - const PrivateKeyEditPage(), - 'private key edit page', - ).go(context), + onPressed: () => AppRoute.keyEdit().go(context), ), ); } @@ -68,10 +64,8 @@ class _PrivateKeyListState extends State ListTile( title: Text(key.pkis[idx].id), trailing: TextButton( - onPressed: () => AppRoute( - PrivateKeyEditPage(pki: key.pkis[idx]), - 'private key edit page', - ).go(context), + onPressed: () => + AppRoute.keyEdit(pki: key.pkis[idx]).go(context), child: Text(_s.edit), ), ), @@ -102,10 +96,7 @@ class _PrivateKeyListState extends State TextButton( onPressed: () { context.pop(); - AppRoute( - PrivateKeyEditPage(pki: sysPk), - 'private key edit page', - ).go(context); + AppRoute.keyEdit(pki: sysPk).go(context); }, child: Text(_s.ok), ), diff --git a/lib/view/page/server/edit.dart b/lib/view/page/server/edit.dart index e4cc8aaa..1d459d48 100644 --- a/lib/view/page/server/edit.dart +++ b/lib/view/page/server/edit.dart @@ -17,7 +17,6 @@ import '../../../data/store/private_key.dart'; import '../../../locator.dart'; import '../../widget/custom_appbar.dart'; import '../../widget/tag.dart'; -import '../private_key/edit.dart'; class ServerEditPage extends StatefulWidget { const ServerEditPage({Key? key, this.spi}) : super(key: key); @@ -231,10 +230,7 @@ class _ServerEditPageState extends State with AfterLayoutMixin { contentPadding: EdgeInsets.zero, trailing: IconButton( icon: const Icon(Icons.add), - onPressed: () => AppRoute( - const PrivateKeyEditPage(), - 'private key edit page', - ).go(context), + onPressed: () => AppRoute.keyEdit().go(context), ), ), ); diff --git a/lib/view/page/server/tab.dart b/lib/view/page/server/tab.dart index cadbde2b..36e6e281 100644 --- a/lib/view/page/server/tab.dart +++ b/lib/view/page/server/tab.dart @@ -23,7 +23,6 @@ import '../../../locator.dart'; import '../../widget/round_rect_card.dart'; import '../../widget/server_func_btns.dart'; import '../../widget/tag.dart'; -import 'edit.dart'; class ServerPage extends StatefulWidget { const ServerPage({Key? key}) : super(key: key); @@ -63,10 +62,7 @@ class _ServerPageState extends State return Scaffold( body: _buildBody(), floatingActionButton: FloatingActionButton( - onPressed: () => AppRoute( - const ServerEditPage(), - 'Add server info page', - ).go(context), + onPressed: () => AppRoute.serverEdit().go(context), tooltip: _s.addAServer, heroTag: 'server', child: const Icon(Icons.add), diff --git a/lib/view/page/setting/entry.dart b/lib/view/page/setting/entry.dart index c21b2e0e..27442149 100644 --- a/lib/view/page/setting/entry.dart +++ b/lib/view/page/setting/entry.dart @@ -13,7 +13,6 @@ import 'package:toolbox/core/extension/stringx.dart'; import 'package:toolbox/core/persistant_store.dart'; import 'package:toolbox/core/route.dart'; import 'package:toolbox/data/model/app/net_view.dart'; -import 'package:toolbox/view/page/setting/virt_key.dart'; import 'package:toolbox/view/widget/input_field.dart'; import 'package:toolbox/view/widget/value_notifier.dart'; @@ -814,10 +813,7 @@ class _SettingPageState extends State { return ListTile( title: Text(_s.editVirtKeys), trailing: const Icon(Icons.keyboard_arrow_right), - onTap: () => AppRoute( - const SSHVirtKeySettingPage(), - 'ssh virt key edit', - ).go(context), + onTap: () => AppRoute.sshVirtKeySetting().go(context), ); } diff --git a/lib/view/page/snippet/list.dart b/lib/view/page/snippet/list.dart index c8cd1d85..69523fb1 100644 --- a/lib/view/page/snippet/list.dart +++ b/lib/view/page/snippet/list.dart @@ -14,7 +14,6 @@ import '../../../locator.dart'; import '../../widget/tag.dart'; import '/core/route.dart'; import '/data/provider/snippet.dart'; -import 'edit.dart'; import '/view/widget/round_rect_card.dart'; class SnippetListPage extends StatefulWidget { @@ -46,10 +45,7 @@ class _SnippetListPageState extends State { floatingActionButton: FloatingActionButton( heroTag: 'snippet', child: const Icon(Icons.add), - onPressed: () => AppRoute( - const SnippetEditPage(), - 'snippet edit page', - ).go(context), + onPressed: () => AppRoute.snippetEdit().go(context), ), ); } @@ -121,10 +117,8 @@ class _SnippetListPageState extends State { mainAxisSize: MainAxisSize.min, children: [ IconButton( - onPressed: () => AppRoute( - SnippetEditPage(snippet: snippet), - 'snippet edit page', - ).go(context), + onPressed: () => + AppRoute.snippetEdit(snippet: snippet).go(context), icon: const Icon(Icons.edit), ), IconButton( diff --git a/lib/view/page/storage/local.dart b/lib/view/page/storage/local.dart index 88395c0c..eae98601 100644 --- a/lib/view/page/storage/local.dart +++ b/lib/view/page/storage/local.dart @@ -8,7 +8,6 @@ import 'package:toolbox/data/provider/server.dart'; import 'package:toolbox/data/provider/sftp.dart'; import 'package:toolbox/data/res/misc.dart'; import 'package:toolbox/locator.dart'; -import 'package:toolbox/view/page/editor.dart'; import 'package:toolbox/view/widget/input_field.dart'; import 'package:toolbox/view/widget/picker.dart'; import 'package:toolbox/view/widget/round_rect_card.dart'; @@ -23,13 +22,15 @@ import '../../../data/res/path.dart'; import '../../../data/res/ui.dart'; import '../../widget/custom_appbar.dart'; import '../../widget/fade_in.dart'; -import 'sftp_mission.dart'; class LocalStoragePage extends StatefulWidget { final bool isPickFile; final String? initDir; - const LocalStoragePage({Key? key, this.isPickFile = false, this.initDir}) - : super(key: key); + const LocalStoragePage({ + Key? key, + required this.isPickFile, + this.initDir, + }) : super(key: key); @override State createState() => _LocalStoragePageState(); @@ -78,10 +79,7 @@ class _LocalStoragePageState extends State { actions: [ IconButton( icon: const Icon(Icons.downloading), - onPressed: () => AppRoute( - const SftpMissionPage(), - 'sftp downloading', - ).go(context), + onPressed: () => AppRoute.sftpMission().go(context), ) ], ), @@ -256,11 +254,8 @@ class _LocalStoragePageState extends State { ); return; } - final result = await AppRoute( - EditorPage( - path: file.absolute.path, - ), - 'sftp dled editor', + final result = await AppRoute.editor( + path: file.absolute.path, ).go(context); final f = File(file.absolute.path); if (result != null) { diff --git a/lib/view/page/storage/sftp.dart b/lib/view/page/storage/sftp.dart index d54bbc81..58006856 100644 --- a/lib/view/page/storage/sftp.dart +++ b/lib/view/page/storage/sftp.dart @@ -9,8 +9,6 @@ import 'package:toolbox/core/extension/navigator.dart'; import 'package:toolbox/core/extension/sftpfile.dart'; import 'package:toolbox/data/res/misc.dart'; import 'package:toolbox/data/store/history.dart'; -import 'package:toolbox/view/page/editor.dart'; -import 'package:toolbox/view/page/storage/local.dart'; import 'package:toolbox/view/widget/round_rect_card.dart'; import '../../../core/extension/numx.dart'; @@ -31,7 +29,6 @@ import '../../widget/custom_appbar.dart'; import '../../widget/fade_in.dart'; import '../../widget/input_field.dart'; import '../../widget/two_line_text.dart'; -import 'sftp_mission.dart'; class SftpPage extends StatefulWidget { final ServerPrivateInfo spi; @@ -92,10 +89,7 @@ class _SftpPageState extends State { actions: [ IconButton( icon: const Icon(Icons.downloading), - onPressed: () => AppRoute( - const SftpMissionPage(), - 'sftp downloading', - ).go(context), + onPressed: () => AppRoute.sftpMission().go(context), ), ], ), @@ -176,11 +170,7 @@ class _SftpPageState extends State { final path = await () async { switch (idx) { case 0: - return await AppRoute( - const LocalStoragePage( - isPickFile: true, - ), - 'sftp dled pick') + return await AppRoute.localStorage(isPickFile: true) .go(context); case 1: return await pickOneFile(); @@ -390,10 +380,7 @@ class _SftpPageState extends State { await completer.future; context.pop(); - final result = await AppRoute( - EditorPage(path: localPath), - 'SFTP edit', - ).go(context); + final result = await AppRoute.editor(path: localPath).go(context); if (result != null) { _sftp.add(SftpReq(req.spi, remotePath, localPath, SftpReqType.upload)); } diff --git a/lib/view/page/storage/sftp_mission.dart b/lib/view/page/storage/sftp_mission.dart index 3fa39b91..8092e41f 100644 --- a/lib/view/page/storage/sftp_mission.dart +++ b/lib/view/page/storage/sftp_mission.dart @@ -5,7 +5,6 @@ import 'package:toolbox/core/extension/datetime.dart'; import 'package:toolbox/core/extension/navigator.dart'; import 'package:toolbox/core/route.dart'; import 'package:toolbox/locator.dart'; -import 'package:toolbox/view/page/storage/local.dart'; import '../../../core/extension/numx.dart'; import '../../../core/utils/misc.dart'; @@ -77,10 +76,7 @@ class _SftpMissionPageState extends State { onPressed: () { final idx = status.req.localPath.lastIndexOf('/'); final dir = status.req.localPath.substring(0, idx); - AppRoute( - LocalStoragePage(initDir: dir), - 'sftp local', - ).go(context); + AppRoute.localStorage(initDir: dir).go(context); }, icon: const Icon(Icons.file_open)), IconButton( diff --git a/lib/view/widget/server_func_btns.dart b/lib/view/widget/server_func_btns.dart index 13072df2..00a3aed3 100644 --- a/lib/view/widget/server_func_btns.dart +++ b/lib/view/widget/server_func_btns.dart @@ -14,7 +14,6 @@ import '../../data/model/server/server_private_info.dart'; import '../../data/model/server/snippet.dart'; import '../../data/provider/snippet.dart'; import '../../locator.dart'; -import '../page/process.dart'; import 'tag.dart'; class ServerFuncBtns extends StatelessWidget { @@ -84,7 +83,7 @@ class ServerFuncBtns extends StatelessWidget { ); break; case ServerTabMenuType.process: - AppRoute(ProcessPage(spi: spi), 'process page').checkGo( + AppRoute.process(spi: spi).checkGo( context: context, check: () => _checkClient(context, spi.id), );