From 7b1c1b9a5a65a40b81d5eba62e3dc0ea623c0f8f Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Mon, 5 Jun 2023 17:51:52 +0800 Subject: [PATCH] opt. for performance --- ios/Runner.xcodeproj/project.pbxproj | 12 +-- lib/core/utils/ui.dart | 2 +- lib/data/model/app/tab.dart | 22 +++++- lib/data/res/build_data.dart | 6 +- lib/data/res/url.dart | 2 +- lib/data/store/setting.dart | 8 -- lib/view/page/docker.dart | 2 +- lib/view/page/home.dart | 75 ++++++------------- lib/view/page/ping.dart | 4 +- lib/view/page/private_key/edit.dart | 7 +- lib/view/page/server/edit.dart | 2 +- lib/view/page/server/tab.dart | 26 +------ lib/view/page/setting.dart | 14 ---- lib/view/widget/{tag.dart => tag_editor.dart} | 0 macos/Runner.xcodeproj/project.pbxproj | 12 +-- 15 files changed, 68 insertions(+), 126 deletions(-) rename lib/view/widget/{tag.dart => tag_editor.dart} (100%) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 9acdffbb..300237f0 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -360,7 +360,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 347; + CURRENT_PROJECT_VERSION = 353; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; @@ -368,7 +368,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.347; + MARKETING_VERSION = 1.0.353; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -491,7 +491,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 347; + CURRENT_PROJECT_VERSION = 353; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; @@ -499,7 +499,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.347; + MARKETING_VERSION = 1.0.353; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -516,7 +516,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 347; + CURRENT_PROJECT_VERSION = 353; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; @@ -524,7 +524,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.347; + MARKETING_VERSION = 1.0.353; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; diff --git a/lib/core/utils/ui.dart b/lib/core/utils/ui.dart index 09719982..9368aee4 100644 --- a/lib/core/utils/ui.dart +++ b/lib/core/utils/ui.dart @@ -103,7 +103,7 @@ void setTransparentNavigationBar(BuildContext context) { String tabTitleName(BuildContext context, AppTab tab) { final s = S.of(context)!; switch (tab) { - case AppTab.servers: + case AppTab.server: return s.server; case AppTab.snippet: return s.convert; diff --git a/lib/data/model/app/tab.dart b/lib/data/model/app/tab.dart index a869491d..cbe34b2f 100644 --- a/lib/data/model/app/tab.dart +++ b/lib/data/model/app/tab.dart @@ -1 +1,21 @@ -enum AppTab { servers, snippet, ping } +import 'package:flutter/material.dart'; +import 'package:toolbox/view/page/ping.dart'; +import 'package:toolbox/view/page/server/tab.dart'; +import 'package:toolbox/view/page/snippet/list.dart'; + +enum AppTab { + server, + snippet, + ping; + + Widget get page { + switch (this) { + case server: + return const ServerPage(); + case snippet: + return const SnippetListPage(); + case ping: + return const PingPage(); + } + } +} diff --git a/lib/data/res/build_data.dart b/lib/data/res/build_data.dart index 1c35d1d8..cfb020b4 100644 --- a/lib/data/res/build_data.dart +++ b/lib/data/res/build_data.dart @@ -2,8 +2,8 @@ class BuildData { static const String name = "ServerBox"; - static const int build = 347; + static const int build = 353; static const String engine = "3.10.3"; - static const String buildAt = "2023-06-04 22:37:44.679072"; - static const int modifications = 7; + static const String buildAt = "2023-06-05 17:15:25.298942"; + static const int modifications = 6; } diff --git a/lib/data/res/url.dart b/lib/data/res/url.dart index e640d065..bb09ef16 100644 --- a/lib/data/res/url.dart +++ b/lib/data/res/url.dart @@ -2,7 +2,7 @@ const backendUrl = 'https://res.lolli.tech'; const baseUrl = '$backendUrl/serverbox'; const joinQQGroupUrl = 'https://jq.qq.com/?_wv=1027&k=G0hUmPAq'; const myGithub = 'https://github.com/lollipopkit'; -const issueUrl = '$myGithub/flutter_server_box/issues'; +const appHelpUrl = '$myGithub/flutter_server_box#-help'; // Thanks const thanksMap = { diff --git a/lib/data/store/setting.dart b/lib/data/store/setting.dart index 17b8cba8..0cc23557 100644 --- a/lib/data/store/setting.dart +++ b/lib/data/store/setting.dart @@ -24,14 +24,6 @@ class SettingStore extends PersistentStore { StoreProperty get storeVersion => property('storeVersion', defaultValue: 0); - // Show logo on server detail page - StoreProperty get showDistLogo => - property('showDistLogo', defaultValue: true); - - // First time to use SSH term - StoreProperty get firstTimeUseSshTerm => - property('firstTimeUseSshTerm', defaultValue: true); - StoreProperty get termColorIdx => property('termColorIdx', defaultValue: 0); diff --git a/lib/view/page/docker.dart b/lib/view/page/docker.dart index 6dbeb907..5eab7add 100644 --- a/lib/view/page/docker.dart +++ b/lib/view/page/docker.dart @@ -419,7 +419,7 @@ class _DockerManagePageState extends State { return Text(_s.waitConnection); case DockerErrType.invalidVersion: return UrlText( - text: _s.invalidVersionHelp(issueUrl), + text: _s.invalidVersionHelp(appHelpUrl), replace: 'Github', ); default: diff --git a/lib/view/page/home.dart b/lib/view/page/home.dart index e4ed3ba8..e89426e0 100644 --- a/lib/view/page/home.dart +++ b/lib/view/page/home.dart @@ -2,11 +2,11 @@ import 'package:after_layout/after_layout.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:get_it/get_it.dart'; -import 'package:toolbox/core/extension/navigator.dart'; import 'package:toolbox/data/model/app/tab.dart'; import 'package:toolbox/data/provider/app.dart'; import 'package:toolbox/data/res/misc.dart'; import 'package:toolbox/view/widget/round_rect_card.dart'; +import 'package:toolbox/view/widget/value_notifier.dart'; import '../../core/analysis.dart'; import '../../core/route.dart'; @@ -23,12 +23,9 @@ import '../widget/url_text.dart'; import 'backup.dart'; import 'convert.dart'; import 'debug.dart'; -import 'ping.dart'; import 'private_key/list.dart'; -import 'server/tab.dart'; import 'setting.dart'; import 'sftp/local.dart'; -import 'snippet/list.dart'; class HomePage extends StatefulWidget { const HomePage({Key? key}) : super(key: key); @@ -47,19 +44,19 @@ class _HomePageState extends State late final PageController _pageController; - late int _selectIndex; + final _selectIndex = ValueNotifier(0); late S _s; @override void initState() { super.initState(); WidgetsBinding.instance.addObserver(this); - _selectIndex = _setting.launchPage.fetch()!; + _selectIndex.value = _setting.launchPage.fetch()!; // avoid index out of range - if (_selectIndex >= AppTab.values.length || _selectIndex < 0) { - _selectIndex = 0; + if (_selectIndex.value >= AppTab.values.length || _selectIndex.value < 0) { + _selectIndex.value = 0; } - _pageController = PageController(initialPage: _selectIndex); + _pageController = PageController(initialPage: _selectIndex.value); } @override @@ -120,34 +117,27 @@ class _HomePageState extends State ), ], ), - body: PageView( - physics: const ClampingScrollPhysics(), + body: PageView.builder( + physics: const NeverScrollableScrollPhysics(), controller: _pageController, - onPageChanged: (index) { - setState(() { - _selectIndex = index; - FocusScope.of(context).requestFocus(FocusNode()); - }); - }, - children: const [ServerPage(), SnippetListPage(), PingPage()], + itemBuilder: (_, index) => AppTab.values[index].page, ), - bottomNavigationBar: _buildBottomBar(context), + bottomNavigationBar: + ValueBuilder(listenable: _selectIndex, build: _buildBottomBar), ); } - Widget _buildBottomBar(BuildContext context) { + Widget _buildBottomBar() { return NavigationBar( - selectedIndex: _selectIndex, + selectedIndex: _selectIndex.value, animationDuration: const Duration(milliseconds: 250), onDestinationSelected: (int index) { - setState(() { - _selectIndex = index; - _pageController.animateToPage( - index, - duration: const Duration(milliseconds: 677), - curve: Curves.fastLinearToSlowEaseIn, - ); - }); + _selectIndex.value = index; + _pageController.animateToPage( + index, + duration: const Duration(milliseconds: 677), + curve: Curves.fastLinearToSlowEaseIn, + ); }, labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected, destinations: [ @@ -189,9 +179,7 @@ class _HomePageState extends State style: textSize13, ), ), - SizedBox( - height: MediaQuery.of(context).size.height * 0.07, - ), + const SizedBox(height: 37), Padding( padding: const EdgeInsets.symmetric(horizontal: 17), child: Column( @@ -264,17 +252,13 @@ class _HomePageState extends State ), actions: [ TextButton( - onPressed: () => openUrl(issueUrl), + onPressed: () => openUrl(appHelpUrl), child: Text(_s.feedback), ), TextButton( onPressed: () => showLicensePage(context: context), child: Text(_s.license), ), - TextButton( - onPressed: () => context.pop(), - child: Text(_s.close), - ) ], ); }, @@ -288,20 +272,9 @@ class _HomePageState extends State } Widget _buildIcon() { - return Stack( - alignment: Alignment.center, - children: [ - ConstrainedBox( - constraints: const BoxConstraints(maxHeight: 53, maxWidth: 53), - child: Container( - color: Colors.white, - ), - ), - ConstrainedBox( - constraints: const BoxConstraints(maxHeight: 83, maxWidth: 83), - child: appIcon, - ) - ], + return ConstrainedBox( + constraints: const BoxConstraints(maxHeight: 57, maxWidth: 57), + child: appIcon, ); } diff --git a/lib/view/page/ping.dart b/lib/view/page/ping.dart index 10c8935a..830f499c 100644 --- a/lib/view/page/ping.dart +++ b/lib/view/page/ping.dart @@ -82,10 +82,10 @@ class _PingPageState extends State ); } - void _doPing() { + Future _doPing() async { context.pop(); try { - doPing(); + await doPing(); } catch (e) { showRoundDialog( context: context, diff --git a/lib/view/page/private_key/edit.dart b/lib/view/page/private_key/edit.dart index cfefbb65..e44af7dc 100644 --- a/lib/view/page/private_key/edit.dart +++ b/lib/view/page/private_key/edit.dart @@ -97,12 +97,7 @@ class _PrivateKeyEditPageState extends State } FocusScope.of(context).unfocus(); setState(() { - _loading = const SizedBox( - height: 50, - child: Center( - child: CircularProgressIndicator(), - ), - ); + _loading = centerSizedLoading; }); final info = PrivateKeyInfo(name, key, ''); try { diff --git a/lib/view/page/server/edit.dart b/lib/view/page/server/edit.dart index cc2ab8fc..650472b1 100644 --- a/lib/view/page/server/edit.dart +++ b/lib/view/page/server/edit.dart @@ -14,7 +14,7 @@ import '../../../data/provider/server.dart'; import '../../../data/res/ui.dart'; import '../../../data/store/private_key.dart'; import '../../../locator.dart'; -import '../../widget/tag.dart'; +import '../../widget/tag_editor.dart'; import '../private_key/edit.dart'; class ServerEditPage extends StatefulWidget { diff --git a/lib/view/page/server/tab.dart b/lib/view/page/server/tab.dart index 2a7ef6ee..3a11cdb7 100644 --- a/lib/view/page/server/tab.dart +++ b/lib/view/page/server/tab.dart @@ -17,12 +17,10 @@ import '../../../data/provider/server.dart'; import '../../../data/res/color.dart'; import '../../../data/model/app/menu.dart'; import '../../../data/res/ui.dart'; -import '../../../data/res/url.dart'; import '../../../data/store/setting.dart'; import '../../../locator.dart'; import '../../widget/popup_menu.dart'; import '../../widget/round_rect_card.dart'; -import '../../widget/url_text.dart'; import '../docker.dart'; import '../pkg.dart'; import '../sftp/remote.dart'; @@ -303,29 +301,7 @@ class _ServerPageState extends State Icons.terminal, size: 21, ), - onTap: () async { - if (_settingStore.firstTimeUseSshTerm.fetch()!) { - await showRoundDialog( - context: context, - child: UrlText( - text: _s.sshTip(issueUrl), - replace: 'Github Issue', - ), - actions: [ - TextButton( - onPressed: () { - _settingStore.firstTimeUseSshTerm.put(false); - context.pop(); - AppRoute(SSHPage(spi: spi), 'ssh page').go(context); - }, - child: Text(_s.ok), - ) - ], - ); - } else { - AppRoute(SSHPage(spi: spi), 'ssh page').go(context); - } - }, + onTap: () => AppRoute(SSHPage(spi: spi), 'ssh page').go(context), ); } diff --git a/lib/view/page/setting.dart b/lib/view/page/setting.dart index 15e76a0f..c164452b 100644 --- a/lib/view/page/setting.dart +++ b/lib/view/page/setting.dart @@ -142,7 +142,6 @@ class _SettingPageState extends State { Widget _buildServer() { return Column( children: [ - _buildDistLogoSwitch(), _buildUpdateInterval(), _buildMaxRetry(), _buildDiskIgnorePath(), @@ -168,19 +167,6 @@ class _SettingPageState extends State { ); } - Widget _buildDistLogoSwitch() { - return ListTile( - title: Text( - _s.showDistLogo, - ), - subtitle: Text( - _s.onServerDetailPage, - style: grey, - ), - trailing: buildSwitch(context, _setting.showDistLogo), - ); - } - Widget _buildCheckUpdate() { return Consumer( builder: (_, app, __) { diff --git a/lib/view/widget/tag.dart b/lib/view/widget/tag_editor.dart similarity index 100% rename from lib/view/widget/tag.dart rename to lib/view/widget/tag_editor.dart diff --git a/macos/Runner.xcodeproj/project.pbxproj b/macos/Runner.xcodeproj/project.pbxproj index bc48d2a2..50f03a4b 100644 --- a/macos/Runner.xcodeproj/project.pbxproj +++ b/macos/Runner.xcodeproj/project.pbxproj @@ -475,9 +475,9 @@ baseConfigurationReference = C1C758C41C4E208965A68933 /* Pods-RunnerTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - CURRENT_PROJECT_VERSION = 347; + CURRENT_PROJECT_VERSION = 353; GENERATE_INFOPLIST_FILE = YES; - MARKETING_VERSION = 1.0.347; + MARKETING_VERSION = 1.0.353; PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -490,9 +490,9 @@ baseConfigurationReference = 15AF97DF993E8968098D6EBE /* Pods-RunnerTests.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - CURRENT_PROJECT_VERSION = 347; + CURRENT_PROJECT_VERSION = 353; GENERATE_INFOPLIST_FILE = YES; - MARKETING_VERSION = 1.0.347; + MARKETING_VERSION = 1.0.353; PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -505,9 +505,9 @@ baseConfigurationReference = 7CFA7DE7FABA75685DFB6948 /* Pods-RunnerTests.profile.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - CURRENT_PROJECT_VERSION = 347; + CURRENT_PROJECT_VERSION = 353; GENERATE_INFOPLIST_FILE = YES; - MARKETING_VERSION = 1.0.347; + MARKETING_VERSION = 1.0.353; PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0;