From 76e8a1efca1dcd5e9b249fb320eb621db2ebac1a Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Tue, 27 Jun 2023 12:52:11 +0800 Subject: [PATCH] new: set light/dark editor theme --- lib/data/res/default.dart | 3 ++- lib/data/res/misc.dart | 2 +- lib/data/store/setting.dart | 3 +++ lib/view/page/server/detail.dart | 4 +++- lib/view/page/setting.dart | 39 +++++++++++++++++++++++++++++++- lib/view/widget/url_text.dart | 33 +++++++++++++++------------ 6 files changed, 66 insertions(+), 18 deletions(-) diff --git a/lib/data/res/default.dart b/lib/data/res/default.dart index daba4e5e..13134b51 100644 --- a/lib/data/res/default.dart +++ b/lib/data/res/default.dart @@ -45,4 +45,5 @@ const defaultLaunchPageIdx = 0; const defaultUpdateInterval = 3; -const defaultEditorTheme = 'monokai'; +const defaultEditorTheme = 'a11y-light'; +const defaultEditorDarkTheme = 'monokai'; diff --git a/lib/data/res/misc.dart b/lib/data/res/misc.dart index 9851ee8c..2e6ec310 100644 --- a/lib/data/res/misc.dart +++ b/lib/data/res/misc.dart @@ -10,7 +10,7 @@ const privateKeyMaxSize = 20 * 1024; const editorMaxSize = 1024 * 1024; /// Max debug log lines -const maxDebugLogLines = 377; +const maxDebugLogLines = 100; /// Method Channels const pkgName = 'tech.lolli.toolbox'; diff --git a/lib/data/store/setting.dart b/lib/data/store/setting.dart index 1e962af2..487c8886 100644 --- a/lib/data/store/setting.dart +++ b/lib/data/store/setting.dart @@ -68,6 +68,9 @@ class SettingStore extends PersistentStore { // Editor theme StoreProperty get editorTheme => property('editorTheme', defaultValue: defaultEditorTheme); + + StoreProperty get editorDarkTheme => + property('editorDarkTheme', defaultValue: defaultEditorDarkTheme); StoreProperty get fullScreen => property('fullScreen', defaultValue: false); diff --git a/lib/view/page/server/detail.dart b/lib/view/page/server/detail.dart index 76f52ed4..68d57079 100644 --- a/lib/view/page/server/detail.dart +++ b/lib/view/page/server/detail.dart @@ -353,7 +353,7 @@ class _ServerDetailPageState extends State } Widget _buildNetSpeedItem(NetSpeed ns, String device) { - final width = (_media.size.width - 34 - 34) / 2.9; + final width = (_media.size.width - 34 - 34) / 3; return Padding( padding: const EdgeInsets.symmetric(vertical: 3), child: Row( @@ -365,6 +365,8 @@ class _ServerDetailPageState extends State device, style: textSize11, textScaleFactor: 1.0, + maxLines: 1, + overflow: TextOverflow.ellipsis, ), ), SizedBox( diff --git a/lib/view/page/setting.dart b/lib/view/page/setting.dart index 50b0e2f9..6dfbf6ba 100644 --- a/lib/view/page/setting.dart +++ b/lib/view/page/setting.dart @@ -43,6 +43,7 @@ class _SettingPageState extends State { final _maxRetryKey = GlobalKey>(); final _localeKey = GlobalKey>(); final _editorThemeKey = GlobalKey>(); + final _editorDarkThemeKey = GlobalKey>(); final _keyboardTypeKey = GlobalKey>(); late final SettingStore _setting; @@ -58,6 +59,7 @@ class _SettingPageState extends State { final _fontSize = ValueNotifier(0.0); final _localeCode = ValueNotifier(''); final _editorTheme = ValueNotifier(''); + final _editorDarkTheme = ValueNotifier(''); final _keyboardType = ValueNotifier(0); final _pushToken = ValueNotifier(null); @@ -82,6 +84,7 @@ class _SettingPageState extends State { _selectedColorValue.value = _setting.primaryColor.fetch()!; _fontSize.value = _setting.termFontSize.fetch()!; _editorTheme.value = _setting.editorTheme.fetch()!; + _editorDarkTheme.value = _setting.editorDarkTheme.fetch()!; _keyboardType.value = _setting.keyboardType.fetch()!; } @@ -176,6 +179,7 @@ class _SettingPageState extends State { return Column( children: [ _buildEditorTheme(), + _buildEditorDarkTheme(), ].map((e) => RoundRectCard(e)).toList(), ); } @@ -651,7 +655,7 @@ class _SettingPageState extends State { }, ).toList(); return ListTile( - title: Text(_s.theme), + title: Text(_s.light + _s.theme), trailing: ValueBuilder( listenable: _editorTheme, build: () => PopupMenuButton( @@ -674,6 +678,39 @@ class _SettingPageState extends State { ); } + Widget _buildEditorDarkTheme() { + final items = themeMap.keys.map( + (key) { + return PopupMenuItem( + value: key, + child: Text(key), + ); + }, + ).toList(); + return ListTile( + title: Text(_s.dark + _s.theme), + trailing: ValueBuilder( + listenable: _editorDarkTheme, + build: () => PopupMenuButton( + key: _editorDarkThemeKey, + itemBuilder: (BuildContext context) => items, + initialValue: _editorDarkTheme.value, + onSelected: (String idx) { + _editorDarkTheme.value = idx; + _setting.editorDarkTheme.put(idx); + }, + child: Text( + _editorDarkTheme.value, + style: textSize15, + ), + ), + ), + onTap: () { + _editorDarkThemeKey.currentState?.showButtonMenu(); + }, + ); + } + Widget _buildFullScreenSwitch() { return ListTile( title: Text(_s.fullScreen), diff --git a/lib/view/widget/url_text.dart b/lib/view/widget/url_text.dart index 1c6ec11c..e00722ea 100644 --- a/lib/view/widget/url_text.dart +++ b/lib/view/widget/url_text.dart @@ -23,8 +23,8 @@ class UrlText extends StatelessWidget { this.style = _textStyle, }) : super(key: key); - List _getTextSpans(Color c) { - List widgets = []; + List getTextSpans(Color c) { + final widgets = []; Iterable matches = _reg.allMatches(text); List<_ResultMatch> resultMatches = <_ResultMatch>[]; int start = 0; @@ -33,24 +33,27 @@ class UrlText extends StatelessWidget { final group0 = match.group(0); if (group0 != null && group0.isNotEmpty) { if (start != match.start) { - _ResultMatch result1 = _ResultMatch(); - result1.isUrl = false; - result1.text = text.substring(start, match.start); + _ResultMatch result1 = _ResultMatch( + false, + text.substring(start, match.start), + ); resultMatches.add(result1); } - _ResultMatch result2 = _ResultMatch(); - result2.isUrl = true; - result2.text = match.group(0)!; + _ResultMatch result2 = _ResultMatch( + true, + match.group(0)!, + ); resultMatches.add(result2); start = match.end; } } if (start < text.length) { - _ResultMatch result1 = _ResultMatch(); - result1.isUrl = false; - result1.text = text.substring(start); + _ResultMatch result1 = _ResultMatch( + false, + text.substring(start), + ); resultMatches.add(result1); } @@ -81,7 +84,7 @@ class UrlText extends StatelessWidget { Widget build(BuildContext context) { return RichText( textAlign: textAlign ?? TextAlign.start, - text: TextSpan(children: _getTextSpans(contentColor.resolve(context))), + text: TextSpan(children: getTextSpans(contentColor.resolve(context))), ); } } @@ -99,6 +102,8 @@ class _LinkTextSpan extends TextSpan { } class _ResultMatch { - late bool isUrl; - late String text; + final bool isUrl; + final String text; + + _ResultMatch(this.isUrl, this.text); }