new: set light/dark editor theme

This commit is contained in:
lollipopkit
2023-06-27 12:52:11 +08:00
parent 9ffe5583fd
commit 76e8a1efca
6 changed files with 66 additions and 18 deletions

View File

@@ -45,4 +45,5 @@ const defaultLaunchPageIdx = 0;
const defaultUpdateInterval = 3; const defaultUpdateInterval = 3;
const defaultEditorTheme = 'monokai'; const defaultEditorTheme = 'a11y-light';
const defaultEditorDarkTheme = 'monokai';

View File

@@ -10,7 +10,7 @@ const privateKeyMaxSize = 20 * 1024;
const editorMaxSize = 1024 * 1024; const editorMaxSize = 1024 * 1024;
/// Max debug log lines /// Max debug log lines
const maxDebugLogLines = 377; const maxDebugLogLines = 100;
/// Method Channels /// Method Channels
const pkgName = 'tech.lolli.toolbox'; const pkgName = 'tech.lolli.toolbox';

View File

@@ -69,6 +69,9 @@ class SettingStore extends PersistentStore {
StoreProperty<String> get editorTheme => StoreProperty<String> get editorTheme =>
property('editorTheme', defaultValue: defaultEditorTheme); property('editorTheme', defaultValue: defaultEditorTheme);
StoreProperty<String> get editorDarkTheme =>
property('editorDarkTheme', defaultValue: defaultEditorDarkTheme);
StoreProperty<bool> get fullScreen => StoreProperty<bool> get fullScreen =>
property('fullScreen', defaultValue: false); property('fullScreen', defaultValue: false);

View File

@@ -353,7 +353,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
} }
Widget _buildNetSpeedItem(NetSpeed ns, String device) { 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( return Padding(
padding: const EdgeInsets.symmetric(vertical: 3), padding: const EdgeInsets.symmetric(vertical: 3),
child: Row( child: Row(
@@ -365,6 +365,8 @@ class _ServerDetailPageState extends State<ServerDetailPage>
device, device,
style: textSize11, style: textSize11,
textScaleFactor: 1.0, textScaleFactor: 1.0,
maxLines: 1,
overflow: TextOverflow.ellipsis,
), ),
), ),
SizedBox( SizedBox(

View File

@@ -43,6 +43,7 @@ class _SettingPageState extends State<SettingPage> {
final _maxRetryKey = GlobalKey<PopupMenuButtonState<int>>(); final _maxRetryKey = GlobalKey<PopupMenuButtonState<int>>();
final _localeKey = GlobalKey<PopupMenuButtonState<String>>(); final _localeKey = GlobalKey<PopupMenuButtonState<String>>();
final _editorThemeKey = GlobalKey<PopupMenuButtonState<String>>(); final _editorThemeKey = GlobalKey<PopupMenuButtonState<String>>();
final _editorDarkThemeKey = GlobalKey<PopupMenuButtonState<String>>();
final _keyboardTypeKey = GlobalKey<PopupMenuButtonState<int>>(); final _keyboardTypeKey = GlobalKey<PopupMenuButtonState<int>>();
late final SettingStore _setting; late final SettingStore _setting;
@@ -58,6 +59,7 @@ class _SettingPageState extends State<SettingPage> {
final _fontSize = ValueNotifier(0.0); final _fontSize = ValueNotifier(0.0);
final _localeCode = ValueNotifier(''); final _localeCode = ValueNotifier('');
final _editorTheme = ValueNotifier(''); final _editorTheme = ValueNotifier('');
final _editorDarkTheme = ValueNotifier('');
final _keyboardType = ValueNotifier(0); final _keyboardType = ValueNotifier(0);
final _pushToken = ValueNotifier<String?>(null); final _pushToken = ValueNotifier<String?>(null);
@@ -82,6 +84,7 @@ class _SettingPageState extends State<SettingPage> {
_selectedColorValue.value = _setting.primaryColor.fetch()!; _selectedColorValue.value = _setting.primaryColor.fetch()!;
_fontSize.value = _setting.termFontSize.fetch()!; _fontSize.value = _setting.termFontSize.fetch()!;
_editorTheme.value = _setting.editorTheme.fetch()!; _editorTheme.value = _setting.editorTheme.fetch()!;
_editorDarkTheme.value = _setting.editorDarkTheme.fetch()!;
_keyboardType.value = _setting.keyboardType.fetch()!; _keyboardType.value = _setting.keyboardType.fetch()!;
} }
@@ -176,6 +179,7 @@ class _SettingPageState extends State<SettingPage> {
return Column( return Column(
children: [ children: [
_buildEditorTheme(), _buildEditorTheme(),
_buildEditorDarkTheme(),
].map((e) => RoundRectCard(e)).toList(), ].map((e) => RoundRectCard(e)).toList(),
); );
} }
@@ -651,7 +655,7 @@ class _SettingPageState extends State<SettingPage> {
}, },
).toList(); ).toList();
return ListTile( return ListTile(
title: Text(_s.theme), title: Text(_s.light + _s.theme),
trailing: ValueBuilder( trailing: ValueBuilder(
listenable: _editorTheme, listenable: _editorTheme,
build: () => PopupMenuButton( build: () => PopupMenuButton(
@@ -674,6 +678,39 @@ class _SettingPageState extends State<SettingPage> {
); );
} }
Widget _buildEditorDarkTheme() {
final items = themeMap.keys.map(
(key) {
return PopupMenuItem<String>(
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() { Widget _buildFullScreenSwitch() {
return ListTile( return ListTile(
title: Text(_s.fullScreen), title: Text(_s.fullScreen),

View File

@@ -23,8 +23,8 @@ class UrlText extends StatelessWidget {
this.style = _textStyle, this.style = _textStyle,
}) : super(key: key); }) : super(key: key);
List<InlineSpan> _getTextSpans(Color c) { List<InlineSpan> getTextSpans(Color c) {
List<InlineSpan> widgets = <InlineSpan>[]; final widgets = <InlineSpan>[];
Iterable<Match> matches = _reg.allMatches(text); Iterable<Match> matches = _reg.allMatches(text);
List<_ResultMatch> resultMatches = <_ResultMatch>[]; List<_ResultMatch> resultMatches = <_ResultMatch>[];
int start = 0; int start = 0;
@@ -33,24 +33,27 @@ class UrlText extends StatelessWidget {
final group0 = match.group(0); final group0 = match.group(0);
if (group0 != null && group0.isNotEmpty) { if (group0 != null && group0.isNotEmpty) {
if (start != match.start) { if (start != match.start) {
_ResultMatch result1 = _ResultMatch(); _ResultMatch result1 = _ResultMatch(
result1.isUrl = false; false,
result1.text = text.substring(start, match.start); text.substring(start, match.start),
);
resultMatches.add(result1); resultMatches.add(result1);
} }
_ResultMatch result2 = _ResultMatch(); _ResultMatch result2 = _ResultMatch(
result2.isUrl = true; true,
result2.text = match.group(0)!; match.group(0)!,
);
resultMatches.add(result2); resultMatches.add(result2);
start = match.end; start = match.end;
} }
} }
if (start < text.length) { if (start < text.length) {
_ResultMatch result1 = _ResultMatch(); _ResultMatch result1 = _ResultMatch(
result1.isUrl = false; false,
result1.text = text.substring(start); text.substring(start),
);
resultMatches.add(result1); resultMatches.add(result1);
} }
@@ -81,7 +84,7 @@ class UrlText extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return RichText( return RichText(
textAlign: textAlign ?? TextAlign.start, 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 { class _ResultMatch {
late bool isUrl; final bool isUrl;
late String text; final String text;
_ResultMatch(this.isUrl, this.text);
} }