支持脚本的编辑删除

This commit is contained in:
jyuesong
2022-01-20 10:25:10 +08:00
parent 89ad8e38e5
commit 22f66d36a2
11 changed files with 703 additions and 147 deletions

View File

@@ -5,6 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.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/routes.dart';
import 'package:qinglong_app/base/theme.dart';
import 'package:qinglong_app/base/ui/lazy_load_state.dart';
import 'package:qinglong_app/utils/extension.dart';
@@ -27,6 +28,105 @@ class ScriptDetailPage extends ConsumerStatefulWidget {
class _ScriptDetailPageState extends ConsumerState<ScriptDetailPage> with LazyLoadState<ScriptDetailPage> {
String? content;
List<Widget> actions = [];
@override
void initState() {
super.initState();
actions.addAll(
[
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).pop();
if (content == null || content!.isEmpty) {
"未获取到脚本内容,请稍候重试".toast();
return;
}
Navigator.of(context).pushNamed(
Routes.routeScriptUpdate,
arguments: {
"title": widget.title,
"path": widget.path,
"content": content,
},
).then((value) {
if (value != null && value == true) {
Navigator.of(context).pop(true);
}
});
},
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 15,
),
alignment: Alignment.center,
child: const Material(
color: Colors.transparent,
child: Text(
"编辑",
style: TextStyle(
fontSize: 16,
),
),
),
),
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () async {
Navigator.of(context).pop();
showCupertinoDialog(
context: context,
builder: (context) => CupertinoAlertDialog(
title: const Text("确认删除"),
content: const Text("确认删除该脚本吗"),
actions: [
CupertinoDialogAction(
child: const Text("取消"),
onPressed: () {
Navigator.of(context).pop();
},
),
CupertinoDialogAction(
child: const Text("确定"),
onPressed: () async {
Navigator.of(context).pop();
HttpResponse<NullResponse> result = await Api.delScript(widget.title, widget.path ?? "");
if (result.success) {
"删除成功".toast();
Navigator.of(context).pop(true);
} else {
result.message?.toast();
}
},
),
],
),
);
},
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 15,
),
alignment: Alignment.center,
child: const Material(
color: Colors.transparent,
child: Text(
"删除",
style: TextStyle(
color: Colors.red,
fontSize: 16,
),
),
),
),
),
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -36,22 +136,82 @@ class _ScriptDetailPageState extends ConsumerState<ScriptDetailPage> with LazyLo
Navigator.of(context).pop();
},
title: "脚本详情",
),
body:content == null
? const Center(
child: CupertinoActivityIndicator(),
)
: SingleChildScrollView(
child: HighlightView(
content ?? "",
language: getLanguageType(widget.title),
padding: const EdgeInsets.symmetric(
horizontal: 15,
actions: [
InkWell(
onTap: () {
showCupertinoModalPopup(
context: context,
builder: (context) {
return CupertinoActionSheet(
title: Container(
alignment: Alignment.center,
child: const Material(
color: Colors.transparent,
child: Text(
"更多操作",
style: TextStyle(
fontSize: 16,
),
),
),
),
actions: actions,
cancelButton: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.pop(context);
},
child: Container(
alignment: Alignment.center,
padding: const EdgeInsets.symmetric(
vertical: 10,
),
child: const Material(
color: Colors.transparent,
child: Text(
"取消",
style: TextStyle(
color: Colors.red,
fontSize: 16,
),
),
),
),
),
);
},
);
},
child: const Padding(
padding: EdgeInsets.symmetric(
horizontal: 15,
),
child: Center(
child: Icon(
Icons.more_horiz,
color: Colors.white,
size: 26,
),
),
),
),
theme: ref.watch(themeProvider).themeColor.codeEditorTheme(),
tabSize: 14,
),
],
),
body: content == null
? 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,
),
),
);
}