new: editor custom theme
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
import 'package:code_text_field/code_text_field.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_code_editor/flutter_code_editor.dart';
|
||||
import 'package:flutter_highlight/themes/monokai-sublime.dart';
|
||||
import 'package:highlight/languages/java.dart';
|
||||
import 'package:flutter_highlight/theme_map.dart';
|
||||
import 'package:flutter_highlight/themes/monokai.dart';
|
||||
import 'package:toolbox/core/extension/navigator.dart';
|
||||
import 'package:toolbox/data/res/highlight.dart';
|
||||
import 'package:toolbox/data/store/setting.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
|
||||
class EditorPage extends StatefulWidget {
|
||||
final String? initCode;
|
||||
const EditorPage({Key? key, this.initCode}) : super(key: key);
|
||||
final String? fileName;
|
||||
const EditorPage({Key? key, this.initCode, this.fileName}) : super(key: key);
|
||||
|
||||
@override
|
||||
_EditorPageState createState() => _EditorPageState();
|
||||
@@ -15,16 +19,18 @@ class EditorPage extends StatefulWidget {
|
||||
class _EditorPageState extends State<EditorPage> {
|
||||
late CodeController _controller;
|
||||
late final _focusNode = FocusNode();
|
||||
final _setting = locator<SettingStore>();
|
||||
late Map<String, TextStyle> _codeTheme;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_focusNode.requestFocus();
|
||||
_controller = CodeController(
|
||||
text: widget.initCode,
|
||||
language: java,
|
||||
analyzer: const DefaultLocalAnalyzer(),
|
||||
);
|
||||
text: widget.initCode,
|
||||
language: widget.fileName.highlight,
|
||||
);
|
||||
_codeTheme = themeMap[_setting.editorTheme.fetch()] ?? monokaiTheme;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -37,28 +43,23 @@ class _EditorPageState extends State<EditorPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: monokaiSublimeTheme['root']!.backgroundColor,
|
||||
backgroundColor: _codeTheme['root']!.backgroundColor,
|
||||
appBar: AppBar(
|
||||
title: const Text('Editor'),
|
||||
title: Text(widget.fileName ?? ''),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.done),
|
||||
onPressed: () {
|
||||
context.pop(_controller.fullText);
|
||||
context.pop(_controller.text);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: CodeTheme(
|
||||
data: CodeThemeData(styles: monokaiSublimeTheme),
|
||||
child: SingleChildScrollView(
|
||||
child: CodeField(
|
||||
controller: _controller,
|
||||
gutterStyle: const GutterStyle(
|
||||
width: 37,
|
||||
showLineNumbers: false,
|
||||
),
|
||||
),
|
||||
data: CodeThemeData(styles: _codeTheme),
|
||||
child: CodeField(
|
||||
controller: _controller,
|
||||
textStyle: const TextStyle(fontFamily: 'SourceCode'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user