mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: implemnt export editor state
This commit is contained in:
parent
ba5c1804ce
commit
778b55d44e
@ -1,4 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@ -8,6 +9,7 @@ import 'expandable_floating_action_button.dart';
|
||||
import 'plugin/youtube_link_node_widget.dart';
|
||||
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
@ -58,6 +60,7 @@ class MyHomePage extends StatefulWidget {
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
final editorKey = GlobalKey();
|
||||
int page = 0;
|
||||
EditorState? _editorState;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -103,6 +106,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
..handler = (message) {
|
||||
debugPrint(message);
|
||||
};
|
||||
_editorState = editorState;
|
||||
return _buildAppFlowyEditor(editorState);
|
||||
} else {
|
||||
return const Center(
|
||||
@ -146,6 +150,21 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
);
|
||||
}
|
||||
|
||||
void _exportDocument(EditorState editorState) async {
|
||||
// await FileSaver.instance.saveAs(String name, Uint8List bytes, String ext, MimeType);
|
||||
final document = editorState.document.toJson();
|
||||
debugPrint(document.toString());
|
||||
final json = jsonEncode(document);
|
||||
debugPrint(json);
|
||||
|
||||
final directory = await getTemporaryDirectory();
|
||||
final path = directory.path;
|
||||
debugPrint(path);
|
||||
|
||||
final file = File('$path/temp.json');
|
||||
await file.writeAsString(json);
|
||||
}
|
||||
|
||||
Widget _buildExpandableFab() {
|
||||
return ExpandableFab(
|
||||
distance: 112.0,
|
||||
@ -177,6 +196,12 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
},
|
||||
icon: const Icon(Icons.text_fields),
|
||||
),
|
||||
ActionButton(
|
||||
onPressed: () {
|
||||
_exportDocument(_editorState!);
|
||||
},
|
||||
icon: const Icon(Icons.print),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -6,10 +6,14 @@
|
||||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <file_saver/file_saver_plugin.h>
|
||||
#include <rich_clipboard_linux/rich_clipboard_plugin.h>
|
||||
#include <url_launcher_linux/url_launcher_plugin.h>
|
||||
|
||||
void fl_register_plugins(FlPluginRegistry* registry) {
|
||||
g_autoptr(FlPluginRegistrar) file_saver_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSaverPlugin");
|
||||
file_saver_plugin_register_with_registrar(file_saver_registrar);
|
||||
g_autoptr(FlPluginRegistrar) rich_clipboard_linux_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "RichClipboardPlugin");
|
||||
rich_clipboard_plugin_register_with_registrar(rich_clipboard_linux_registrar);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
file_saver
|
||||
rich_clipboard_linux
|
||||
url_launcher_linux
|
||||
)
|
||||
|
@ -5,11 +5,15 @@
|
||||
import FlutterMacOS
|
||||
import Foundation
|
||||
|
||||
import file_saver
|
||||
import path_provider_macos
|
||||
import rich_clipboard_macos
|
||||
import url_launcher_macos
|
||||
import wakelock_macos
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
FileSaverPlugin.register(with: registry.registrar(forPlugin: "FileSaverPlugin"))
|
||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||
RichClipboardPlugin.register(with: registry.registrar(forPlugin: "RichClipboardPlugin"))
|
||||
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
|
||||
WakelockMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockMacosPlugin"))
|
||||
|
@ -1,5 +1,9 @@
|
||||
PODS:
|
||||
- file_saver (0.0.1):
|
||||
- FlutterMacOS
|
||||
- FlutterMacOS (1.0.0)
|
||||
- path_provider_macos (0.0.1):
|
||||
- FlutterMacOS
|
||||
- rich_clipboard_macos (0.0.1):
|
||||
- FlutterMacOS
|
||||
- url_launcher_macos (0.0.1):
|
||||
@ -8,14 +12,20 @@ PODS:
|
||||
- FlutterMacOS
|
||||
|
||||
DEPENDENCIES:
|
||||
- file_saver (from `Flutter/ephemeral/.symlinks/plugins/file_saver/macos`)
|
||||
- FlutterMacOS (from `Flutter/ephemeral`)
|
||||
- path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`)
|
||||
- rich_clipboard_macos (from `Flutter/ephemeral/.symlinks/plugins/rich_clipboard_macos/macos`)
|
||||
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)
|
||||
- wakelock_macos (from `Flutter/ephemeral/.symlinks/plugins/wakelock_macos/macos`)
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
file_saver:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/file_saver/macos
|
||||
FlutterMacOS:
|
||||
:path: Flutter/ephemeral
|
||||
path_provider_macos:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos
|
||||
rich_clipboard_macos:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/rich_clipboard_macos/macos
|
||||
url_launcher_macos:
|
||||
@ -24,7 +34,9 @@ EXTERNAL SOURCES:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/wakelock_macos/macos
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
file_saver: 44e6fbf666677faf097302460e214e977fdd977b
|
||||
FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424
|
||||
path_provider_macos: 3c0c3b4b0d4a76d2bf989a913c2de869c5641a19
|
||||
rich_clipboard_macos: 43364b66b9dc69d203eb8dd6d758e2d12e02723c
|
||||
url_launcher_macos: 597e05b8e514239626bcf4a850fcf9ef5c856ec3
|
||||
wakelock_macos: bc3f2a9bd8d2e6c89fee1e1822e7ddac3bd004a9
|
||||
|
@ -40,6 +40,7 @@ dependencies:
|
||||
video_player: ^2.4.5
|
||||
pod_player: 0.0.8
|
||||
flutter_inappwebview: ^5.4.3+7
|
||||
file_saver: ^0.1.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
@ -6,9 +6,12 @@
|
||||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <file_saver/file_saver_plugin.h>
|
||||
#include <url_launcher_windows/url_launcher_windows.h>
|
||||
|
||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
FileSaverPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("FileSaverPlugin"));
|
||||
UrlLauncherWindowsRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
file_saver
|
||||
url_launcher_windows
|
||||
)
|
||||
|
||||
|
@ -163,7 +163,8 @@ class Node extends ChangeNotifier with LinkedListEntry<Node> {
|
||||
'type': type,
|
||||
};
|
||||
if (children.isNotEmpty) {
|
||||
map['children'] = children.map((node) => node.toJson());
|
||||
map['children'] =
|
||||
(children.map((node) => node.toJson())).toList(growable: false);
|
||||
}
|
||||
if (_attributes.isNotEmpty) {
|
||||
map['attributes'] = _attributes;
|
||||
|
@ -33,6 +33,12 @@ class StateTree {
|
||||
return StateTree(root: root);
|
||||
}
|
||||
|
||||
Map<String, Object> toJson() {
|
||||
return {
|
||||
'document': root.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
Node? nodeAtPath(Path path) {
|
||||
return root.childAtPath(path);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user