mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
add function
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import 'package:code_editor/code_editor.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:qinglong_app/base/common_dialog.dart';
|
||||
import 'package:qinglong_app/base/http/api.dart';
|
||||
import 'package:qinglong_app/base/http/http.dart';
|
||||
import 'package:qinglong_app/base/ql_app_bar.dart';
|
||||
import 'package:qinglong_app/base/theme.dart';
|
||||
import 'package:qinglong_app/module/config/config_viewmodel.dart';
|
||||
import 'package:qinglong_app/utils/qinglong_theme.dart';
|
||||
|
||||
class ConfigEditPage extends ConsumerStatefulWidget {
|
||||
final String content;
|
||||
@@ -21,34 +20,23 @@ class ConfigEditPage extends ConsumerStatefulWidget {
|
||||
class _ConfigEditPageState extends ConsumerState<ConfigEditPage> {
|
||||
String? value;
|
||||
|
||||
late TextEditingController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_controller = TextEditingController(text: widget.content);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<FileEditor> files = [
|
||||
FileEditor(
|
||||
name: widget.title,
|
||||
language: "sh",
|
||||
code: widget.content, // [code] needs a string
|
||||
),
|
||||
];
|
||||
EditorModel editMode = EditorModel(
|
||||
files: files,
|
||||
styleOptions: EditorModelStyleOptions(
|
||||
fontSize: 13,
|
||||
heightOfContainer: MediaQuery.of(context).size.height - kToolbarHeight - kBottomNavigationBarHeight - 150,
|
||||
editorBorderColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
editButtonBackgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
editorColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
theme: qinglongLightTheme,
|
||||
),
|
||||
|
||||
);
|
||||
return Scaffold(
|
||||
appBar: QlAppBar(
|
||||
canBack: true,
|
||||
backCall: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
title: '编辑文件',
|
||||
title: '编辑${widget.title}',
|
||||
actions: [
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
@@ -56,7 +44,7 @@ class _ConfigEditPageState extends ConsumerState<ConfigEditPage> {
|
||||
failDialog(context, "请先点击保存");
|
||||
return;
|
||||
}
|
||||
HttpResponse<NullResponse> response = await Api.saveFile(widget.title, value!);
|
||||
HttpResponse<NullResponse> response = await Api.saveFile(widget.title, _controller.text);
|
||||
if (response.success) {
|
||||
ref.read(configProvider).loadContent(widget.title);
|
||||
Navigator.of(context).pop();
|
||||
@@ -76,13 +64,21 @@ class _ConfigEditPageState extends ConsumerState<ConfigEditPage> {
|
||||
],
|
||||
),
|
||||
body: Container(
|
||||
child: CodeEditor(
|
||||
model: editMode,
|
||||
edit: true,
|
||||
onSubmit: (title, v) {
|
||||
value = v;
|
||||
},
|
||||
disableNavigationbar: false,
|
||||
padding: const EdgeInsets.only(
|
||||
left: 15,
|
||||
right: 15,
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
child: TextField(
|
||||
focusNode: FocusNode(),
|
||||
style: TextStyle(
|
||||
color: ref.read(themeProvider).themeColor.descColor(),
|
||||
fontSize: 14,
|
||||
),
|
||||
controller: _controller,
|
||||
minLines: 1,
|
||||
maxLines: 100,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:qinglong_app/base/base_state_widget.dart';
|
||||
import 'package:code_editor/code_editor.dart';
|
||||
import 'package:qinglong_app/base/code_editor/code_editor.dart';
|
||||
import 'package:qinglong_app/base/code_editor/EditorModel.dart';
|
||||
import 'package:qinglong_app/base/code_editor/EditorModelStyleOptions.dart';
|
||||
import 'package:qinglong_app/base/code_editor/FileEditor.dart';
|
||||
import 'package:qinglong_app/base/http/url.dart';
|
||||
import 'package:qinglong_app/base/routes.dart';
|
||||
import 'package:qinglong_app/base/theme.dart';
|
||||
import 'package:qinglong_app/utils/qinglong_theme.dart';
|
||||
import 'package:qinglong_app/main.dart';
|
||||
|
||||
import 'config_viewmodel.dart';
|
||||
|
||||
@@ -10,10 +16,12 @@ class ConfigPage extends StatefulWidget {
|
||||
const ConfigPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ConfigPageState createState() => _ConfigPageState();
|
||||
ConfigPageState createState() => ConfigPageState();
|
||||
}
|
||||
|
||||
class _ConfigPageState extends State<ConfigPage> {
|
||||
class ConfigPageState extends State<ConfigPage> {
|
||||
GlobalKey<CodeEditorState> globalKey = GlobalKey();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BaseStateWidget<ConfigViewModel>(
|
||||
@@ -31,6 +39,7 @@ class _ConfigPageState extends State<ConfigPage> {
|
||||
files: files,
|
||||
styleOptions: EditorModelStyleOptions(
|
||||
fontSize: 13,
|
||||
editorNormalFilenameColor: ref.read(themeProvider).themeColor.descColor(),
|
||||
heightOfContainer: MediaQuery.of(context).size.height - kToolbarHeight - kBottomNavigationBarHeight - 90,
|
||||
editorBorderColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
editButtonBackgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
@@ -40,6 +49,7 @@ class _ConfigPageState extends State<ConfigPage> {
|
||||
),
|
||||
);
|
||||
return CodeEditor(
|
||||
key: globalKey,
|
||||
model: editMode,
|
||||
edit: false,
|
||||
disableNavigationbar: false,
|
||||
@@ -51,4 +61,11 @@ class _ConfigPageState extends State<ConfigPage> {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void editMe(WidgetRef ref) {
|
||||
int index = globalKey.currentState?.getCurrentIndex() ?? 0;
|
||||
|
||||
navigatorState.currentState?.pushNamed(Routes.route_ConfigEdit,
|
||||
arguments: {"title": ref.read(configProvider).list[index].title, "content": ref.read(configProvider).content[ref.read(configProvider).list[index].title]});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user