Skip to content

Commit

Permalink
feat: Android 代码编辑
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaoMint committed Jul 6, 2023
1 parent 8ce0324 commit f509e65
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 20 deletions.
68 changes: 52 additions & 16 deletions lib/pages/code_edit/view.dart
Original file line number Diff line number Diff line change
@@ -1,34 +1,70 @@
import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_code_editor/flutter_code_editor.dart';
import 'package:miru_app/models/extension.dart';
import 'package:miru_app/utils/extension.dart';
import 'package:miru_app/widgets/messenger.dart';
import 'package:highlight/languages/javascript.dart';
import 'package:flutter_highlight/themes/monokai-sublime.dart';

class CodeEditPage extends StatefulWidget {
const CodeEditPage({
required this.extension,
Key? key,
required this.windowController,
required this.args,
}) : super(key: key);
final WindowController windowController;
final Map? args;
final Extension extension;
@override
State<CodeEditPage> createState() => _CodeEditPageState();
}

class _CodeEditPageState extends State<CodeEditPage> {
CodeController controller = CodeController();
CodeController controller = CodeController(
language: javascript,
);

@override
void initState() {
_init();
super.initState();
}

_init() async {
final dir = await ExtensionUtils.getExtensionsDir;
final file = File('$dir/${widget.extension.package}.js');
if (await file.exists()) {
final content = await file.readAsString();
controller.text = content;
}
}

_save() async {
final dir = await ExtensionUtils.getExtensionsDir;
final file = File('$dir/${widget.extension.package}.js');
await file.writeAsString(controller.text);
// ignore: use_build_context_synchronously
showPlatformSnackbar(context: context, title: '保存代码', content: '保存成功');
}

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Miru',
debugShowCheckedModeBanner: false,
home: Scaffold(
body: CodeTheme(
data: CodeThemeData(),
child: SingleChildScrollView(
child: CodeField(
controller: controller,
),
return Scaffold(
appBar: AppBar(
title: Text(widget.extension.name),
actions: [
IconButton(
onPressed: () async {
_save();
},
icon: const Icon(Icons.save),
),
],
),
body: CodeTheme(
data: CodeThemeData(styles: monokaiSublimeTheme),
child: SingleChildScrollView(
child: CodeField(
controller: controller,
),
),
),
Expand Down
36 changes: 34 additions & 2 deletions lib/pages/extension/widgets/extension_tile.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'package:fluent_ui/fluent_ui.dart' as fluent;
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:miru_app/models/extension.dart';
import 'package:miru_app/pages/code_edit/view.dart';
import 'package:miru_app/utils/extension.dart';
import 'package:miru_app/widgets/cache_network_image.dart';
import 'package:miru_app/widgets/messenger.dart';
import 'package:miru_app/widgets/platform_widget.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:path/path.dart' as path;
Expand Down Expand Up @@ -46,11 +49,40 @@ class _ExtensionTileState extends State<ExtensionTile> {
subtitle: Text(
'${widget.extension.version} ${_extensionTypeToString(widget.extension.type)} ',
),
onTap: () {
showPlatformSnackbar(context: context, title: '😣', content: '还没写的(');
},
trailing: IconButton(
onPressed: () {
ExtensionUtils.uninstall(widget.extension.package);
// 弹出菜单
showModalBottomSheet(
context: context,
builder: (context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Icon(Icons.code),
title: const Text('编辑代码'),
onTap: () async {
Get.back();
Get.to(CodeEditPage(extension: widget.extension));
},
),
ListTile(
leading: const Icon(Icons.delete),
title: const Text('卸载'),
onTap: () {
ExtensionUtils.uninstall(widget.extension.package);
Get.back();
},
),
],
);
},
);
},
icon: const Icon(Icons.delete),
icon: const Icon(Icons.more_vert),
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ packages:
source: hosted
version: "0.3.0"
flutter_highlight:
dependency: transitive
dependency: "direct main"
description:
name: flutter_highlight
sha256: "7b96333867aa07e122e245c033b8ad622e4e3a42a1a2372cbb098a2541d8782c"
Expand Down Expand Up @@ -438,7 +438,7 @@ packages:
source: hosted
version: "2.3.1"
highlight:
dependency: transitive
dependency: "direct main"
description:
name: highlight
sha256: "5353a83ffe3e3eca7df0abfb72dcf3fa66cc56b953728e7113ad4ad88497cf21"
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ dependencies:
sdk: flutter
flutter_animate: ^4.1.1+1
flutter_code_editor: ^0.3.0
flutter_highlight: ^0.7.0
flutter_js: ^0.7.1
flutter_markdown: ^0.6.16
get: ^4.6.5
go_router: ^8.0.5
highlight: ^0.7.0
hive: ^2.2.3
hive_flutter: ^1.1.0
isar: ^3.1.0+1
Expand Down

0 comments on commit f509e65

Please sign in to comment.