Fix editor on open

This commit is contained in:
Your Name
2023-07-28 15:04:19 +07:00
parent df4836458f
commit 177b3ab66a

View File

@@ -29,7 +29,7 @@ class _EditorPageState extends State<EditorPage> with AfterLayoutMixin {
late CodeController _controller; late CodeController _controller;
late final _focusNode = FocusNode(); late final _focusNode = FocusNode();
final _setting = locator<SettingStore>(); final _setting = locator<SettingStore>();
late Map<String, TextStyle> _codeTheme; Map<String, TextStyle>? _codeTheme;
late S _s; late S _s;
late String? _langCode; late String? _langCode;
@@ -41,13 +41,15 @@ class _EditorPageState extends State<EditorPage> with AfterLayoutMixin {
language: suffix2HighlightMap[_langCode], language: suffix2HighlightMap[_langCode],
); );
if (isDarkMode(context)) { WidgetsBinding.instance.addPostFrameCallback((Duration duration) async {
_codeTheme = themeMap[_setting.editorDarkTheme.fetch()] ?? monokaiTheme; if (isDarkMode(context)) {
} else { _codeTheme = themeMap[_setting.editorDarkTheme.fetch()] ?? monokaiTheme;
_codeTheme = themeMap[_setting.editorTheme.fetch()] ?? a11yLightTheme; } else {
} _codeTheme = themeMap[_setting.editorTheme.fetch()] ?? a11yLightTheme;
}
_focusNode.requestFocus(); _focusNode.requestFocus();
setState(() {});
});
} }
@override @override
@@ -66,7 +68,12 @@ class _EditorPageState extends State<EditorPage> with AfterLayoutMixin {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: _codeTheme['root']!.backgroundColor, backgroundColor: () {
if (_codeTheme != null) {
return _codeTheme!['root']!.backgroundColor;
}
return null;
}(),
appBar: AppBar( appBar: AppBar(
centerTitle: true, centerTitle: true,
title: TwoLineText(up: getFileName(widget.path) ?? '', down: _s.editor), title: TwoLineText(up: getFileName(widget.path) ?? '', down: _s.editor),
@@ -89,15 +96,21 @@ class _EditorPageState extends State<EditorPage> with AfterLayoutMixin {
) )
], ],
), ),
body: SingleChildScrollView( body: Visibility(
child: CodeTheme( visible: (_codeTheme != null),
data: CodeThemeData(styles: _codeTheme), replacement: const Center(
child: CodeField( child: CircularProgressIndicator(),
focusNode: _focusNode, ),
controller: _controller, child: SingleChildScrollView(
lineNumberStyle: const LineNumberStyle( child: CodeTheme(
width: 47, data: CodeThemeData(styles: _codeTheme ?? (isDarkMode(context) ? monokaiTheme : a11yLightTheme)),
margin: 7, child: CodeField(
focusNode: _focusNode,
controller: _controller,
lineNumberStyle: const LineNumberStyle(
width: 47,
margin: 7,
),
), ),
), ),
), ),