Kaynağa Gözat

feat: add empty document entry in example

Lucas.Xu 2 yıl önce
ebeveyn
işleme
eb7c65aa8b

+ 40 - 0
frontend/app_flowy/packages/flowy_editor/example/lib/main.dart

@@ -1,3 +1,4 @@
+import 'dart:collection';
 import 'dart:convert';
 
 import 'package:example/expandable_floating_action_button.dart';
@@ -80,12 +81,21 @@ class _MyHomePageState extends State<MyHomePage> {
             icon: const Icon(Icons.note_add),
           ),
           ActionButton(
+            icon: const Icon(Icons.document_scanner),
             onPressed: () {
               if (page == 1) return;
               setState(() {
                 page = 1;
               });
             },
+          ),
+          ActionButton(
+            onPressed: () {
+              if (page == 2) return;
+              setState(() {
+                page = 2;
+              });
+            },
             icon: const Icon(Icons.text_fields),
           ),
         ],
@@ -97,11 +107,41 @@ class _MyHomePageState extends State<MyHomePage> {
     if (page == 0) {
       return _buildFlowyEditor();
     } else if (page == 1) {
+      return _buildFlowyEditorWithEmptyDocument();
+    } else if (page == 2) {
       return _buildTextField();
     }
     return Container();
   }
 
+  Widget _buildFlowyEditorWithEmptyDocument() {
+    return Container(
+      padding: const EdgeInsets.only(left: 20, right: 20),
+      child: FlowyEditor(
+        key: editorKey,
+        editorState: EditorState(
+          document: StateTree(
+            root: Node(
+              type: 'editor',
+              children: LinkedList()
+                ..add(
+                  TextNode.empty()
+                    ..delta = Delta(
+                      [TextInsert('')],
+                    ),
+                ),
+              attributes: {},
+            ),
+          ),
+        ),
+        keyEventHandlers: const [],
+        customBuilders: {
+          'image': ImageNodeBuilder(),
+        },
+      ),
+    );
+  }
+
   Widget _buildFlowyEditor() {
     return FutureBuilder<String>(
       future: rootBundle.loadString('assets/example.json'),