11// ignore_for_file: use_build_context_synchronously
22
33import 'dart:convert' ;
4- import 'dart:typed_data' ;
54import 'dart:async' ;
5+ import 'package:flutter/foundation.dart' ;
66import 'package:flutter/material.dart' ;
77import 'package:code_text_field/code_text_field.dart' ;
8-
9- // --- 核心语言包 ---
108import 'package:highlight/languages/dart.dart' ;
119import 'package:highlight/languages/javascript.dart' ;
1210import 'package:highlight/languages/python.dart' ;
1311import 'package:highlight/languages/java.dart' ;
1412import 'package:highlight/languages/cpp.dart' ;
1513import 'package:highlight/languages/yaml.dart' ;
1614import 'package:highlight/languages/bash.dart' ;
17- // --- 新增语言支持 ---
1815import 'package:highlight/languages/json.dart' ;
19- import 'package:highlight/languages/xml.dart' ; // 支持 HTML 和 XML
16+ import 'package:highlight/languages/xml.dart' ;
2017import 'package:highlight/languages/css.dart' ;
2118import 'package:highlight/languages/markdown.dart' ;
2219import 'package:highlight/languages/go.dart' ;
@@ -26,8 +23,6 @@ import 'package:highlight/languages/sql.dart';
2623import 'package:highlight/languages/kotlin.dart' ;
2724import 'package:highlight/languages/swift.dart' ;
2825import 'package:highlight/languages/makefile.dart' ;
29-
30- // 高亮主题
3126import 'package:flutter_highlight/themes/monokai-sublime.dart' ;
3227import 'package:flutter_highlight/themes/github.dart' ;
3328
@@ -55,17 +50,19 @@ class _FileEditorPageState extends State<FileEditorPage> {
5550 bool _isModified = false ;
5651 bool _isSaving = false ;
5752 bool _showSearch = false ;
53+ bool get ismobile =>
54+ defaultTargetPlatform == TargetPlatform .android ||
55+ defaultTargetPlatform == TargetPlatform .ohos ||
56+ defaultTargetPlatform == TargetPlatform .iOS;
5857
5958 final TextEditingController _findController = TextEditingController ();
6059 final TextEditingController _replaceController = TextEditingController ();
6160
62- // 历史记录栈
6361 final List <String > _history = [];
6462 int _historyIndex = - 1 ;
6563 bool _isIgnoringListener = false ;
6664 Timer ? _historyTimer;
6765
68- // 扩展后的语言字典
6966 final Map <String , dynamic > _languages = {
7067 'Bash' : bash,
7168 'C++' : cpp,
@@ -92,7 +89,6 @@ class _FileEditorPageState extends State<FileEditorPage> {
9289 @override
9390 void initState () {
9491 super .initState ();
95- // 根据后缀名简单初始化语言逻辑(可选)
9692 _currentLangKey = _detectLanguage (widget.filename);
9793
9894 _codeController = CodeController (
@@ -105,7 +101,6 @@ class _FileEditorPageState extends State<FileEditorPage> {
105101 _codeController.addListener (_handleTextChange);
106102 }
107103
108- // 自动根据后缀识别语言
109104 String _detectLanguage (String filename) {
110105 String ext = filename.split ('.' ).last.toLowerCase ();
111106 switch (ext) {
@@ -146,8 +141,6 @@ class _FileEditorPageState extends State<FileEditorPage> {
146141 }
147142 }
148143
149- // --- 逻辑处理 ---
150-
151144 void _handleTextChange () {
152145 if (_isIgnoringListener) return ;
153146 if (! _isModified && _codeController.text != widget.initialContent) {
@@ -181,8 +174,6 @@ class _FileEditorPageState extends State<FileEditorPage> {
181174 }
182175 }
183176
184- // --- 样式辅助 ---
185-
186177 Color _getAppBarColor () {
187178 return Theme .of (context).brightness == Brightness .dark
188179 ? const Color (0xFF1E1E1E )
@@ -192,7 +183,6 @@ class _FileEditorPageState extends State<FileEditorPage> {
192183 @override
193184 Widget build (BuildContext context) {
194185 final isDark = Theme .of (context).brightness == Brightness .dark;
195- final isMobile = MediaQuery .of (context).size.width < 600 ;
196186
197187 return PopScope (
198188 canPop: false ,
@@ -204,21 +194,20 @@ class _FileEditorPageState extends State<FileEditorPage> {
204194 },
205195 child: Scaffold (
206196 backgroundColor: isDark ? const Color (0xFF1E1E1E ) : Colors .white,
207- // 1. 高度定制的 AppBar
208197 appBar: AppBar (
209198 toolbarHeight: 40 ,
210199 backgroundColor: _getAppBarColor (),
211200 foregroundColor: Colors .white,
212201 titleSpacing: 0 ,
213202 automaticallyImplyLeading: false ,
214- leading: isMobile
203+ leading: ismobile
215204 ? null
216205 : IconButton (
217206 icon: const Icon (Icons .arrow_back, size: 20 ),
218207 onPressed: () => Navigator .of (context).pop (),
219208 ),
220209 title: Padding (
221- padding: EdgeInsets .only (left: isMobile ? 18.0 : 0 ),
210+ padding: EdgeInsets .only (left: ismobile ? 18.0 : 0 ),
222211 child: Column (
223212 mainAxisAlignment: MainAxisAlignment .center,
224213 crossAxisAlignment: CrossAxisAlignment .start,
@@ -234,7 +223,9 @@ class _FileEditorPageState extends State<FileEditorPage> {
234223 children: [
235224 Icon (
236225 _isModified ? Icons .circle : Icons .circle_outlined,
237- color: _isModified ? Colors .orange : Colors .white70,
226+ color: _isModified
227+ ? Theme .of (context).primaryColor
228+ : Colors .white70,
238229 size: 8 ,
239230 ),
240231 const SizedBox (width: 4 ),
@@ -253,7 +244,6 @@ class _FileEditorPageState extends State<FileEditorPage> {
253244 ),
254245 ),
255246 actions: [
256- // 只保留保存按钮
257247 IconButton (
258248 icon: Icon (_isSaving ? Icons .hourglass_empty : Icons .save,
259249 size: 20 ),
@@ -319,7 +309,6 @@ class _FileEditorPageState extends State<FileEditorPage> {
319309 );
320310 }
321311
322- // 快捷工具栏
323312 Widget _buildShortcutBar (bool isDark) {
324313 return Container (
325314 height: 38 ,
@@ -339,8 +328,6 @@ class _FileEditorPageState extends State<FileEditorPage> {
339328 isDark),
340329 _toolBtn (Icons .text_decrease, "" , () => setState (() => _fontSize-- ),
341330 isDark),
342-
343- // 语言切换下拉
344331 PopupMenuButton <String >(
345332 onSelected: (key) => setState (() {
346333 _currentLangKey = key;
@@ -453,8 +440,8 @@ class _FileEditorPageState extends State<FileEditorPage> {
453440 _isModified = false ;
454441 _isSaving = false ;
455442 });
456- ScaffoldMessenger .of (context). showSnackBar ( const SnackBar (
457- content: Text ('文件已保存' ), behavior : SnackBarBehavior .floating ));
443+ ScaffoldMessenger .of (context)
444+ . showSnackBar ( const SnackBar ( content: Text ('文件已保存' )));
458445 } catch (e) {
459446 setState (() => _isSaving = false );
460447 }
0 commit comments