cache
This commit is contained in:
@@ -20,7 +20,7 @@ typedef TextEditingValueChangeBuilder = Widget Function(TextEditingValue value);
|
||||
|
||||
class EditorPage extends ConsumerStatefulWidget {
|
||||
final String title;
|
||||
final String content;
|
||||
final String? content;
|
||||
final List<Language> languages;
|
||||
final bool supportRemoteDownload;
|
||||
final bool titleEditable;
|
||||
@@ -91,6 +91,18 @@ class _EditorPageState extends ConsumerState<EditorPage> {
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final content = widget.content;
|
||||
if (content != null && oldWidget.content != content) {
|
||||
_controller.text = content;
|
||||
_controller.clearHistory();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_toolbarController.hide(context);
|
||||
@@ -256,59 +268,78 @@ class _EditorPageState extends ConsumerState<EditorPage> {
|
||||
),
|
||||
]),
|
||||
),
|
||||
body: CodeEditor(
|
||||
readOnly: readOnly,
|
||||
autofocus: false,
|
||||
showCursorWhenReadOnly: false,
|
||||
findController: _findController,
|
||||
findBuilder: (context, controller, readOnly) => FindPanel(
|
||||
controller: controller,
|
||||
readOnly: readOnly,
|
||||
isMobileView: isMobileView,
|
||||
),
|
||||
padding: EdgeInsets.only(right: 16),
|
||||
autocompleteSymbols: true,
|
||||
focusNode: _focusNode,
|
||||
scrollbarBuilder: (context, child, details) {
|
||||
return CommonScrollBar(
|
||||
controller: details.controller,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
toolbarController: _toolbarController,
|
||||
indicatorBuilder:
|
||||
(context, editingController, chunkController, notifier) {
|
||||
return Row(
|
||||
children: [
|
||||
DefaultCodeLineNumber(
|
||||
controller: editingController,
|
||||
notifier: notifier,
|
||||
),
|
||||
DefaultCodeChunkIndicator(
|
||||
width: 20,
|
||||
controller: chunkController,
|
||||
notifier: notifier,
|
||||
),
|
||||
],
|
||||
body: Stack(
|
||||
children: [
|
||||
CodeEditor(
|
||||
readOnly: readOnly,
|
||||
autofocus: false,
|
||||
showCursorWhenReadOnly: false,
|
||||
findController: _findController,
|
||||
findBuilder: (context, controller, readOnly) => FindPanel(
|
||||
controller: controller,
|
||||
readOnly: readOnly,
|
||||
isMobileView: isMobileView,
|
||||
),
|
||||
padding: EdgeInsets.only(right: 16),
|
||||
autocompleteSymbols: true,
|
||||
focusNode: _focusNode,
|
||||
scrollbarBuilder: (context, child, details) {
|
||||
return CommonScrollBar(
|
||||
controller: details.controller,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
shortcutsActivatorsBuilder: DefaultCodeShortcutsActivatorsBuilder(),
|
||||
controller: _controller,
|
||||
style: CodeEditorStyle(
|
||||
fontSize: context.textTheme.bodyLarge?.fontSize?.ap,
|
||||
fontFamily: FontFamily.jetBrainsMono.value,
|
||||
codeTheme: CodeHighlightTheme(
|
||||
languages: {
|
||||
if (widget.languages.contains(Language.yaml))
|
||||
'yaml': CodeHighlightThemeMode(mode: langYaml),
|
||||
if (widget.languages.contains(Language.javaScript))
|
||||
'javascript': CodeHighlightThemeMode(mode: langJavascript),
|
||||
if (widget.languages.contains(Language.json))
|
||||
'json': CodeHighlightThemeMode(mode: langJson),
|
||||
},
|
||||
theme: atomOneLightTheme,
|
||||
toolbarController: _toolbarController,
|
||||
indicatorBuilder:
|
||||
(context, editingController, chunkController, notifier) {
|
||||
return Row(
|
||||
children: [
|
||||
DefaultCodeLineNumber(
|
||||
controller: editingController,
|
||||
notifier: notifier,
|
||||
),
|
||||
DefaultCodeChunkIndicator(
|
||||
width: 20,
|
||||
controller: chunkController,
|
||||
notifier: notifier,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
shortcutsActivatorsBuilder:
|
||||
DefaultCodeShortcutsActivatorsBuilder(),
|
||||
controller: _controller,
|
||||
style: CodeEditorStyle(
|
||||
fontSize: context.textTheme.bodyLarge?.fontSize?.ap,
|
||||
fontFamily: FontFamily.jetBrainsMono.value,
|
||||
codeTheme: CodeHighlightTheme(
|
||||
languages: {
|
||||
if (widget.languages.contains(Language.yaml))
|
||||
'yaml': CodeHighlightThemeMode(mode: langYaml),
|
||||
if (widget.languages.contains(Language.javaScript))
|
||||
'javascript': CodeHighlightThemeMode(
|
||||
mode: langJavascript,
|
||||
),
|
||||
if (widget.languages.contains(Language.json))
|
||||
'json': CodeHighlightThemeMode(mode: langJson),
|
||||
},
|
||||
theme: atomOneLightTheme,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
FadeBox(
|
||||
child: widget.content == null
|
||||
? Container(
|
||||
color: context.colorScheme.surface,
|
||||
alignment: Alignment.center,
|
||||
child: SizedBox.square(
|
||||
dimension: 200,
|
||||
child: CommonCircleLoading(),
|
||||
),
|
||||
)
|
||||
: SizedBox.shrink(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -2,9 +2,6 @@ import 'package:fl_clash/common/task.dart';
|
||||
import 'package:fl_clash/controller.dart';
|
||||
import 'package:fl_clash/models/profile.dart';
|
||||
import 'package:fl_clash/pages/editor.dart';
|
||||
import 'package:fl_clash/widgets/fade_box.dart';
|
||||
import 'package:fl_clash/widgets/loading.dart';
|
||||
import 'package:fl_clash/widgets/scaffold.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PreviewProfileView extends StatefulWidget {
|
||||
@@ -44,20 +41,8 @@ class _PreviewProfileViewState extends State<PreviewProfileView> {
|
||||
valueListenable: contentNotifier,
|
||||
builder: (_, content, _) {
|
||||
final title = widget.profile.realLabel;
|
||||
return FadeBox(
|
||||
child: content == null
|
||||
? CommonScaffold(
|
||||
title: title,
|
||||
key: Key('loading'),
|
||||
body: Center(
|
||||
child: SizedBox.square(
|
||||
dimension: 200,
|
||||
child: CommonCircleLoading(),
|
||||
),
|
||||
),
|
||||
)
|
||||
: EditorPage(key: Key('content'), title: title, content: content),
|
||||
);
|
||||
|
||||
return EditorPage(key: Key('content'), title: title, content: content);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user