From 86a700d0bb0e6626ec94c6f2f86c6043d4ced657 Mon Sep 17 00:00:00 2001 From: Junyuan Feng Date: Sun, 16 Jan 2022 15:17:11 +0800 Subject: [PATCH] Optimize layout --- ios/Runner.xcodeproj/project.pbxproj | 12 +-- lib/data/provider/server.dart | 19 ++-- lib/data/res/build_data.dart | 11 +-- lib/view/page/server/tab.dart | 126 +++++++++++++-------------- pubspec.lock | 10 +-- pubspec.yaml | 9 +- 6 files changed, 88 insertions(+), 99 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 1a1e04fb..6b8faeef 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -354,7 +354,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 79; + CURRENT_PROJECT_VERSION = 83; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -362,7 +362,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.79; + MARKETING_VERSION = 1.0.83; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -484,7 +484,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 79; + CURRENT_PROJECT_VERSION = 83; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -492,7 +492,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.79; + MARKETING_VERSION = 1.0.83; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -508,7 +508,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 79; + CURRENT_PROJECT_VERSION = 83; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -516,7 +516,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.79; + MARKETING_VERSION = 1.0.83; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; diff --git a/lib/data/provider/server.dart b/lib/data/provider/server.dart index afc2c575..b6c80a19 100644 --- a/lib/data/provider/server.dart +++ b/lib/data/provider/server.dart @@ -26,11 +26,7 @@ import 'package:toolbox/locator.dart'; /// Because of this function is called by [compute] in [ServerProvider.genClient]. /// https://stackoverflow.com/questions/51998995/invalid-arguments-illegal-argument-in-isolate-message-object-is-a-closure List loadIndentity(String key) { - final watch = Stopwatch()..start(); - final pem = SSHKeyPair.fromPem(key); - watch.stop(); - print('loadIndentity: ${watch.elapsedMilliseconds}ms'); - return pem; + return SSHKeyPair.fromPem(key); } class ServerProvider extends BusyProvider { @@ -150,11 +146,9 @@ class ServerProvider extends BusyProvider { } Future _getData(int idx) async { - final client = _servers[idx].client; final info = _servers[idx].info; - final connected = client != null; final state = _servers[idx].connectionState; - if (!connected || + if (_servers[idx].client == null || state == ServerConnectionState.failed || state == ServerConnectionState.disconnected) { _servers[idx].connectionState = ServerConnectionState.connecting; @@ -169,7 +163,7 @@ class ServerProvider extends BusyProvider { notifyListeners(); } catch (e) { _servers[idx].connectionState = ServerConnectionState.failed; - _servers[idx].status.failedInfo = e.toString(); + _servers[idx].status.failedInfo = e.toString() + ' ## '; notifyListeners(); logger.warning(e); } @@ -230,7 +224,7 @@ class ServerProvider extends BusyProvider { } else { info.status.sysVer = ''; } - + notifyListeners(); } @@ -269,9 +263,8 @@ class ServerProvider extends BusyProvider { if (cpus.isEmpty) { info.status.cpu2Status = emptyCpu2Status; } else { - - info.status.cpu2Status = - info.status.cpu2Status.update(cpus, _getCPUTemp(temp)); + info.status.cpu2Status = + info.status.cpu2Status.update(cpus, _getCPUTemp(temp)); } notifyListeners(); diff --git a/lib/data/res/build_data.dart b/lib/data/res/build_data.dart index 402c3af5..b9cece62 100644 --- a/lib/data/res/build_data.dart +++ b/lib/data/res/build_data.dart @@ -1,9 +1,10 @@ // This file is generated by ./make.dart class BuildData { - static const String name = "ToolBox"; - static const int build = 82; - static const String engine = "Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (4 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n"; - static const String buildAt = "2022-01-11 13:31:16.586591"; - static const int modifications = 3; + static const String name = "ServerBox"; + static const int build = 83; + static const String engine = + "Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (4 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n"; + static const String buildAt = "2022-01-16 15:14:10.759902"; + static const int modifications = 6; } diff --git a/lib/view/page/server/tab.dart b/lib/view/page/server/tab.dart index 0a74f901..cd31520e 100644 --- a/lib/view/page/server/tab.dart +++ b/lib/view/page/server/tab.dart @@ -103,12 +103,9 @@ class _ServerPageState extends State 'Edit server info page') .go(context), child: Padding( - padding: const EdgeInsets.all(13), - child: SizedBox( - height: _media.size.height * 0.147, - child: _buildRealServerCard( - si.status, si.info.name, si.connectionState)), - ), + padding: const EdgeInsets.all(13), + child: _buildRealServerCard( + si.status, si.info.name, si.connectionState)), onTap: () => AppRoute(ServerDetailPage('${si.info.ip}:${si.info.port}'), 'server detail page') .go(context), @@ -142,7 +139,7 @@ class _ServerPageState extends State hasError ? ConstrainedBox( constraints: BoxConstraints( - maxWidth: _media.size.width * 0.57, maxHeight: 17), + maxWidth: _media.size.width * 0.57, maxHeight: 15), child: Marquee( accelerationDuration: const Duration(seconds: 3), accelerationCurve: Curves.linear, @@ -159,20 +156,42 @@ class _ServerPageState extends State height: 17, ), Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - _buildPercentCircle(ss.cpu2Status.usedPercent(), 'CPU'), - _buildPercentCircle(ss.memory.used / ss.memory.total * 100, 'Mem'), - _buildIOData('Net', 'Conn:\n' + ss.tcp.maxConn.toString(), + _buildPercentCircle(ss.cpu2Status.usedPercent()), + _buildPercentCircle(ss.memory.used / ss.memory.total * 100), + _buildIOData('Conn:\n' + ss.tcp.maxConn.toString(), 'Fail:\n' + ss.tcp.fail.toString()), - _buildIOData('Disk', 'Total:\n' + rootDisk.size, + _buildIOData('Total:\n' + rootDisk.size, 'Used:\n' + rootDisk.usedPercent.toString() + '%') ], ), + const SizedBox(height: 13), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + _buildExplainText('CPU'), + _buildExplainText('Mem'), + _buildExplainText('Net'), + _buildExplainText('Disk'), + ], + ) ], ); } + Widget _buildExplainText(String text) { + return SizedBox( + width: _media.size.width * 0.2, + child: Text( + text, + style: const TextStyle(fontSize: 12), + textAlign: TextAlign.center, + textScaleFactor: 1.0, + ), + ); + } + String getTopRightStr(ServerConnectionState cs, String temp, String upTime, String? failedInfo) { switch (cs) { @@ -195,36 +214,24 @@ class _ServerPageState extends State } } - Widget _buildIOData(String title, String up, String down) { + Widget _buildIOData(String up, String down) { final statusTextStyle = TextStyle( fontSize: 9, color: _theme.textTheme.bodyText1!.color!.withAlpha(177)); return SizedBox( width: _media.size.width * 0.2, - height: _media.size.height * 0.1, child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - const SizedBox(), - Column( - children: [ - Text( - up, - style: statusTextStyle, - textAlign: TextAlign.center, - textScaleFactor: 1.0, - ), - const SizedBox(height: 3), - Text( - down + '\n', - style: statusTextStyle, - textAlign: TextAlign.center, - textScaleFactor: 1.0, - ) - ], - ), + const SizedBox(height: 5), Text( - title, - style: const TextStyle(fontSize: 12), + up, + style: statusTextStyle, + textAlign: TextAlign.center, + textScaleFactor: 1.0, + ), + const SizedBox(height: 3), + Text( + down, + style: statusTextStyle, textAlign: TextAlign.center, textScaleFactor: 1.0, ) @@ -233,42 +240,31 @@ class _ServerPageState extends State ); } - Widget _buildPercentCircle(double percent, String title) { + Widget _buildPercentCircle(double percent) { if (percent <= 0) percent = 0.01; if (percent >= 100) percent = 99.9; - var size = _media.size.height * 0.15; return SizedBox( width: _media.size.width * 0.2, - height: _media.size.height * 0.1, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + child: Stack( children: [ - Stack( - children: [ - CircleChart( - progressColor: _primaryColor, - progressNumber: percent, - maxNumber: 100, - width: size, - height: size / 1.5, - ), - Positioned.fill( - child: Center( - child: Text( - '${percent.toStringAsFixed(1)}%', - textAlign: TextAlign.center, - style: const TextStyle(fontSize: 11), - textScaleFactor: 1.0, - ), - ), - ), - ], + Center( + child: CircleChart( + progressColor: _primaryColor, + progressNumber: percent, + maxNumber: 100, + width: 53, + height: 53, + ), ), - Text( - title, - style: const TextStyle(fontSize: 12), - textAlign: TextAlign.center, - textScaleFactor: 1.0, + Positioned.fill( + child: Center( + child: Text( + '${percent.toStringAsFixed(1)}%', + textAlign: TextAlign.center, + style: const TextStyle(fontSize: 11), + textScaleFactor: 1.0, + ), + ), ), ], ), diff --git a/pubspec.lock b/pubspec.lock index f1e4ffd0..2ee598e6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -60,11 +60,9 @@ packages: circle_chart: dependency: "direct main" description: - path: "." - ref: main - resolved-ref: "36a46aaa41690aac96fa808a6e75841464007a3b" - url: "https://github.com/LollipopKit/circle_chart" - source: git + path: "../circle_chart" + relative: true + source: path version: "0.0.3" clipboard: dependency: "direct main" @@ -123,7 +121,7 @@ packages: name: dartssh2 url: "https://pub.dartlang.org" source: hosted - version: "2.3.0-pre" + version: "2.3.1-pre" dio: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 9a1e550d..d5d6f133 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,13 +42,14 @@ dependencies: git: url: https://github.com/Countly/countly-sdk-flutter-bridge.git ref: master - dartssh2: ^2.3.0-pre + dartssh2: ^2.3.1-pre logging: ^1.0.2 flutter_material_color_picker: ^1.1.0+2 circle_chart: - git: - url: https://github.com/LollipopKit/circle_chart - ref: main + # git: + # url: https://github.com/LollipopKit/circle_chart + # ref: main + path: ../circle_chart clipboard: ^0.1.3 r_upgrade: ^0.3.6 pull_to_refresh: ^2.0.0