Fix editor on open
This commit is contained in:
@@ -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],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((Duration duration) async {
|
||||||
if (isDarkMode(context)) {
|
if (isDarkMode(context)) {
|
||||||
_codeTheme = themeMap[_setting.editorDarkTheme.fetch()] ?? monokaiTheme;
|
_codeTheme = themeMap[_setting.editorDarkTheme.fetch()] ?? monokaiTheme;
|
||||||
} else {
|
} else {
|
||||||
_codeTheme = themeMap[_setting.editorTheme.fetch()] ?? a11yLightTheme;
|
_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,9 +96,14 @@ class _EditorPageState extends State<EditorPage> with AfterLayoutMixin {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: SingleChildScrollView(
|
body: Visibility(
|
||||||
|
visible: (_codeTheme != null),
|
||||||
|
replacement: const Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
),
|
||||||
|
child: SingleChildScrollView(
|
||||||
child: CodeTheme(
|
child: CodeTheme(
|
||||||
data: CodeThemeData(styles: _codeTheme),
|
data: CodeThemeData(styles: _codeTheme ?? (isDarkMode(context) ? monokaiTheme : a11yLightTheme)),
|
||||||
child: CodeField(
|
child: CodeField(
|
||||||
focusNode: _focusNode,
|
focusNode: _focusNode,
|
||||||
controller: _controller,
|
controller: _controller,
|
||||||
@@ -102,6 +114,7 @@ class _EditorPageState extends State<EditorPage> with AfterLayoutMixin {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
child: const Icon(Icons.done),
|
child: const Icon(Icons.done),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
|||||||
Reference in New Issue
Block a user