mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
update config_page.dart
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@@ -5,9 +7,12 @@ 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/base/ui/highlight/flutter_highlight.dart';
|
||||
import 'package:qinglong_app/module/config/config_page.dart';
|
||||
import 'package:qinglong_app/module/config/config_viewmodel.dart';
|
||||
import 'package:qinglong_app/utils/extension.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
import '../../base/ui/syntax_highlighter.dart';
|
||||
|
||||
class ConfigEditPage extends ConsumerStatefulWidget {
|
||||
final String content;
|
||||
@@ -61,7 +66,8 @@ class _ConfigEditPageState extends ConsumerState<ConfigEditPage> {
|
||||
actions: [
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
HttpResponse<NullResponse> response = await Api.saveFile(widget.title, text);
|
||||
HttpResponse<NullResponse> response =
|
||||
await Api.saveFile(widget.title, text);
|
||||
if (response.success) {
|
||||
"提交成功".toast();
|
||||
ref.read(configProvider).loadContent(widget.title);
|
||||
@@ -96,7 +102,9 @@ class _ConfigEditPageState extends ConsumerState<ConfigEditPage> {
|
||||
child: SizedBox(
|
||||
height: 30,
|
||||
child: ListView(
|
||||
padding: EdgeInsets.symmetric(horizontal: 15,),
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 15,
|
||||
),
|
||||
scrollDirection: Axis.horizontal,
|
||||
children: [
|
||||
GestureDetector(
|
||||
@@ -106,7 +114,9 @@ class _ConfigEditPageState extends ConsumerState<ConfigEditPage> {
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
border: Border.all(color: ref.watch(themeProvider).primaryColor, width: 1),
|
||||
border: Border.all(
|
||||
color: ref.watch(themeProvider).primaryColor,
|
||||
width: 1),
|
||||
),
|
||||
child: Text(
|
||||
"插入",
|
||||
@@ -135,7 +145,9 @@ class _ConfigEditPageState extends ConsumerState<ConfigEditPage> {
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
border: Border.all(color: ref.watch(themeProvider).primaryColor, width: 1),
|
||||
border: Border.all(
|
||||
color: ref.watch(themeProvider).primaryColor,
|
||||
width: 1),
|
||||
),
|
||||
child: Text(
|
||||
"替换",
|
||||
@@ -159,7 +171,9 @@ class _ConfigEditPageState extends ConsumerState<ConfigEditPage> {
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
border: Border.all(color: ref.watch(themeProvider).primaryColor, width: 1),
|
||||
border: Border.all(
|
||||
color: ref.watch(themeProvider).primaryColor,
|
||||
width: 1),
|
||||
),
|
||||
child: Text(
|
||||
"删除",
|
||||
@@ -183,7 +197,9 @@ class _ConfigEditPageState extends ConsumerState<ConfigEditPage> {
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
border: Border.all(color: ref.watch(themeProvider).primaryColor, width: 1),
|
||||
border: Border.all(
|
||||
color: ref.watch(themeProvider).primaryColor,
|
||||
width: 1),
|
||||
),
|
||||
child: Text(
|
||||
"清空",
|
||||
@@ -208,7 +224,9 @@ class _ConfigEditPageState extends ConsumerState<ConfigEditPage> {
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
border: Border.all(color: ref.watch(themeProvider).primaryColor, width: 1),
|
||||
border: Border.all(
|
||||
color: ref.watch(themeProvider).primaryColor,
|
||||
width: 1),
|
||||
),
|
||||
child: Text(
|
||||
"撤销本次操作",
|
||||
@@ -224,18 +242,7 @@ class _ConfigEditPageState extends ConsumerState<ConfigEditPage> {
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: HighlightView(
|
||||
text,
|
||||
language: "sh",
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 15,
|
||||
),
|
||||
theme: ref.watch(themeProvider).themeColor.codeEditorTheme(),
|
||||
tabSize: 14,
|
||||
),
|
||||
),
|
||||
child: CodeWidget(content: text,),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:qinglong_app/base/base_state_widget.dart';
|
||||
import 'package:qinglong_app/base/routes.dart';
|
||||
import 'package:qinglong_app/base/theme.dart';
|
||||
import 'package:qinglong_app/base/ui/abs_underline_tabindicator.dart';
|
||||
import 'package:qinglong_app/base/ui/empty_widget.dart';
|
||||
import 'package:qinglong_app/base/ui/highlight/flutter_highlight.dart';
|
||||
import 'package:qinglong_app/main.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
import '../../base/ui/syntax_highlighter.dart';
|
||||
import 'config_viewmodel.dart';
|
||||
|
||||
class ConfigPage extends StatefulWidget {
|
||||
@@ -18,7 +20,7 @@ class ConfigPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class ConfigPageState extends State<ConfigPage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
|
||||
int _initIndex = 0;
|
||||
BuildContext? childContext;
|
||||
|
||||
@@ -61,19 +63,8 @@ class ConfigPageState extends State<ConfigPage>
|
||||
child: TabBarView(
|
||||
children: model.list
|
||||
.map(
|
||||
(e) => SingleChildScrollView(
|
||||
child: HighlightView(
|
||||
model.content[e.title] ?? "",
|
||||
language: "sh",
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 15,
|
||||
),
|
||||
theme: ref
|
||||
.watch(themeProvider)
|
||||
.themeColor
|
||||
.codeEditorTheme(),
|
||||
tabSize: 14,
|
||||
),
|
||||
(e) => CodeWidget(
|
||||
content: model.content[e.title] ?? "",
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
@@ -109,4 +100,46 @@ class ConfigPageState extends State<ConfigPage>
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
|
||||
class CodeWidget extends StatefulWidget {
|
||||
final String content;
|
||||
|
||||
const CodeWidget({
|
||||
Key? key,
|
||||
required this.content,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<CodeWidget> createState() => _CodeWidgetState();
|
||||
}
|
||||
|
||||
class _CodeWidgetState extends State<CodeWidget>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SelectableText.rich(
|
||||
TextSpan(
|
||||
style: GoogleFonts.droidSansMono(fontSize: 14).apply(
|
||||
fontSizeFactor: 1,
|
||||
),
|
||||
children: <TextSpan>[
|
||||
DartSyntaxHighlighter(SyntaxHighlighterStyle.lightThemeStyle())
|
||||
.format(widget.content)
|
||||
],
|
||||
),
|
||||
style: DefaultTextStyle.of(context).style.apply(
|
||||
fontSizeFactor: 1,
|
||||
),
|
||||
selectionWidthStyle: BoxWidthStyle.max,
|
||||
selectionHeightStyle: BoxHeightStyle.max,
|
||||
autofocus: true,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
|
||||
@@ -432,6 +432,7 @@ class _LoginPageState extends ConsumerState<LoginPage> {
|
||||
}
|
||||
|
||||
void dealLoginResponse(int response) {
|
||||
isLoading = false;
|
||||
if (response == LoginHelper.success) {
|
||||
Navigator.of(context).pushReplacementNamed(Routes.routeHomePage);
|
||||
} else if (response == LoginHelper.failed) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@@ -6,9 +8,13 @@ import 'package:qinglong_app/base/http/http.dart';
|
||||
import 'package:qinglong_app/base/ql_app_bar.dart';
|
||||
import 'package:qinglong_app/base/routes.dart';
|
||||
import 'package:qinglong_app/base/theme.dart';
|
||||
import 'package:qinglong_app/base/ui/highlight/flutter_highlight.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:qinglong_app/base/ui/lazy_load_state.dart';
|
||||
import 'package:qinglong_app/utils/extension.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
import '../../../base/ui/syntax_highlighter.dart';
|
||||
import '../../config/config_page.dart';
|
||||
|
||||
/// @author NewTab
|
||||
class ScriptDetailPage extends ConsumerStatefulWidget {
|
||||
@@ -25,7 +31,8 @@ class ScriptDetailPage extends ConsumerStatefulWidget {
|
||||
_ScriptDetailPageState createState() => _ScriptDetailPageState();
|
||||
}
|
||||
|
||||
class _ScriptDetailPageState extends ConsumerState<ScriptDetailPage> with LazyLoadState<ScriptDetailPage> {
|
||||
class _ScriptDetailPageState extends ConsumerState<ScriptDetailPage>
|
||||
with LazyLoadState<ScriptDetailPage> {
|
||||
String? content;
|
||||
|
||||
List<Widget> actions = [];
|
||||
@@ -103,7 +110,8 @@ class _ScriptDetailPageState extends ConsumerState<ScriptDetailPage> with LazyLo
|
||||
),
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
HttpResponse<NullResponse> result = await Api.delScript(widget.title, widget.path ?? "");
|
||||
HttpResponse<NullResponse> result =
|
||||
await Api.delScript(widget.title, widget.path ?? "");
|
||||
if (result.success) {
|
||||
"删除成功".toast();
|
||||
Navigator.of(context).pop(true);
|
||||
@@ -211,16 +219,8 @@ class _ScriptDetailPageState extends ConsumerState<ScriptDetailPage> with LazyLo
|
||||
? const Center(
|
||||
child: CupertinoActivityIndicator(),
|
||||
)
|
||||
: SingleChildScrollView(
|
||||
child: HighlightView(
|
||||
content ?? "",
|
||||
language: getLanguageType(widget.title),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 15,
|
||||
),
|
||||
theme: ref.watch(themeProvider).themeColor.codeEditorTheme(),
|
||||
tabSize: 14,
|
||||
),
|
||||
: CodeWidget(
|
||||
content: content ?? "",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user