From 261b8e9d2914878dc110e5ce6cb8f0d6d6ed5585 Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Sat, 3 Jun 2023 21:15:26 +0800 Subject: [PATCH] opt. --- ios/Runner.xcodeproj/project.pbxproj | 12 ++++++------ lib/data/provider/sftp.dart | 9 ++++----- lib/data/res/build_data.dart | 4 ++-- lib/view/page/editor.dart | 27 +++++++++++++++----------- lib/view/page/home.dart | 13 ++++++++++--- lib/view/page/sftp/local.dart | 4 +--- lib/view/page/sftp/remote.dart | 1 + lib/view/page/snippet/list.dart | 3 +++ macos/Runner.xcodeproj/project.pbxproj | 12 ++++++------ 9 files changed, 49 insertions(+), 36 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 2b3a9f4d..b2ff519c 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 = 343; + CURRENT_PROJECT_VERSION = 344; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; @@ -368,7 +368,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.343; + MARKETING_VERSION = 1.0.344; 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 = 343; + CURRENT_PROJECT_VERSION = 344; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; @@ -499,7 +499,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.343; + MARKETING_VERSION = 1.0.344; 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 = 343; + CURRENT_PROJECT_VERSION = 344; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; @@ -524,7 +524,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.343; + MARKETING_VERSION = 1.0.344; 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/sftp.dart b/lib/data/provider/sftp.dart index a2113d66..4ee33a4c 100644 --- a/lib/data/provider/sftp.dart +++ b/lib/data/provider/sftp.dart @@ -8,15 +8,14 @@ class SftpProvider extends ProviderBase { final List _status = []; List get status => _status; - List gets({int? id, String? fileName}) { - var found = []; + Iterable gets({int? id, String? fileName}) { + Iterable found = []; if (id != null) { - found = _status.where((e) => e.id == id).toList(); + found = _status.where((e) => e.id == id); } if (fileName != null) { found = found - .where((e) => e.item.localPath.split('/').last == fileName) - .toList(); + .where((e) => e.item.localPath.split('/').last == fileName); } return found; } diff --git a/lib/data/res/build_data.dart b/lib/data/res/build_data.dart index 140c4bd0..5354f5f4 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 = 343; + static const int build = 344; static const String engine = "3.10.2"; - static const String buildAt = "2023-06-01 16:27:31.059809"; + static const String buildAt = "2023-06-02 22:02:47.585289"; static const int modifications = 4; } diff --git a/lib/view/page/editor.dart b/lib/view/page/editor.dart index 4b8cf527..a1c72294 100644 --- a/lib/view/page/editor.dart +++ b/lib/view/page/editor.dart @@ -1,5 +1,7 @@ +import 'dart:async'; import 'dart:io'; +import 'package:after_layout/after_layout.dart'; import 'package:code_text_field/code_text_field.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; @@ -15,14 +17,13 @@ import '../widget/two_line_text.dart'; class EditorPage extends StatefulWidget { final String? path; - final String? initCode; - const EditorPage({Key? key, this.path, this.initCode}) : super(key: key); + const EditorPage({Key? key, this.path}) : super(key: key); @override _EditorPageState createState() => _EditorPageState(); } -class _EditorPageState extends State { +class _EditorPageState extends State with AfterLayoutMixin { late CodeController _controller; late final _focusNode = FocusNode(); final _setting = locator(); @@ -35,15 +36,9 @@ class _EditorPageState extends State { super.initState(); _langCode = widget.path.highlightCode; _controller = CodeController( - text: widget.initCode, - language: suffix2HighlightMap[_langCode ?? 'plaintext'], + language: suffix2HighlightMap[_langCode], ); _codeTheme = themeMap[_setting.editorTheme.fetch()] ?? monokaiTheme; - if (widget.initCode == null && widget.path != null) { - File(widget.path!) - .readAsString() - .then((value) => _controller.text = value); - } _focusNode.requestFocus(); } @@ -92,7 +87,6 @@ class _EditorPageState extends State { child: CodeField( focusNode: _focusNode, controller: _controller, - textStyle: const TextStyle(fontFamily: 'SourceCode'), ), ), ), @@ -104,4 +98,15 @@ class _EditorPageState extends State { ), ); } + + @override + FutureOr afterFirstLayout(BuildContext context) async { + if (widget.path != null) { + await Future.delayed(const Duration(milliseconds: 233)); + final code = await File(widget.path!).readAsString(); + setState(() { + _controller.text = code; + }); + } + } } diff --git a/lib/view/page/home.dart b/lib/view/page/home.dart index 7d33fff1..e4ed3ba8 100644 --- a/lib/view/page/home.dart +++ b/lib/view/page/home.dart @@ -3,6 +3,7 @@ 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'; @@ -54,6 +55,10 @@ class _HomePageState extends State super.initState(); WidgetsBinding.instance.addObserver(this); _selectIndex = _setting.launchPage.fetch()!; + // avoid index out of range + if (_selectIndex >= AppTab.values.length || _selectIndex < 0) { + _selectIndex = 0; + } _pageController = PageController(initialPage: _selectIndex); } @@ -108,8 +113,10 @@ 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( + const DebugPage(), + 'Debug Page', + ).go(context), ), ], ), @@ -210,7 +217,7 @@ class _HomePageState extends State title: Text(_s.download), onTap: () => AppRoute( const SFTPDownloadedPage(), - 'snippet list', + 'sftp local page', ).go(context), ), ListTile( diff --git a/lib/view/page/sftp/local.dart b/lib/view/page/sftp/local.dart index fed7c894..54d95d7d 100644 --- a/lib/view/page/sftp/local.dart +++ b/lib/view/page/sftp/local.dart @@ -180,11 +180,9 @@ class _SFTPDownloadedPageState extends State { return; } final f = File(file.absolute.path); - final data = await f.readAsString(); final result = await AppRoute( EditorPage( - initCode: data, - path: fileName, + path: file.absolute.path, ), 'sftp dled editor', ).go(context); diff --git a/lib/view/page/sftp/remote.dart b/lib/view/page/sftp/remote.dart index 31571ab2..bcb1f875 100644 --- a/lib/view/page/sftp/remote.dart +++ b/lib/view/page/sftp/remote.dart @@ -328,6 +328,7 @@ class _SFTPPageState extends State { ))); return; } + context.pop(); final remotePath = _getRemotePath(name); final localPath = await _getLocalPath(remotePath); diff --git a/lib/view/page/snippet/list.dart b/lib/view/page/snippet/list.dart index 641f9876..c674be3d 100644 --- a/lib/view/page/snippet/list.dart +++ b/lib/view/page/snippet/list.dart @@ -26,6 +26,9 @@ class _SnippetListPageState extends State { @override Widget build(BuildContext context) { return Scaffold( + appBar: AppBar( + title: Text(_s.snippet), + ), body: _buildBody(), floatingActionButton: FloatingActionButton( heroTag: 'snippet', diff --git a/macos/Runner.xcodeproj/project.pbxproj b/macos/Runner.xcodeproj/project.pbxproj index a00d69a7..17dbc956 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 = 343; + CURRENT_PROJECT_VERSION = 344; GENERATE_INFOPLIST_FILE = YES; - MARKETING_VERSION = 1.0.343; + MARKETING_VERSION = 1.0.344; 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 = 343; + CURRENT_PROJECT_VERSION = 344; GENERATE_INFOPLIST_FILE = YES; - MARKETING_VERSION = 1.0.343; + MARKETING_VERSION = 1.0.344; 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 = 343; + CURRENT_PROJECT_VERSION = 344; GENERATE_INFOPLIST_FILE = YES; - MARKETING_VERSION = 1.0.343; + MARKETING_VERSION = 1.0.344; PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0;