Overview
Node is the fundamental building block of an AppFlowy Editor document. Each node has a type (e.g., “paragraph”, “heading”), attributes (data), and can contain child nodes, forming a tree structure.
Nodes are organized in a linked list structure for efficient traversal and manipulation.
Constructor
Node({
required String type,
String? id,
Node? parent,
Attributes attributes = const {},
Iterable<Node> children = const [],
})
Named Constructors
// Create from JSON
Node.fromJson(Map<String, Object> json)
Parameters
The type of the node (e.g., “paragraph”, “heading”, “bulletedList”).
Unique identifier for the node. Auto-generated if not provided.
Node data/attributes (e.g., delta for text, level for headings).
children
Iterable<Node>
default:"[]"
Child nodes.
Properties
The type identifier of this node.
Unique identifier for the node.
Parent node, or null if this is the root.
Copy of the node’s attributes.
The path from the root to this node (e.g., [0], [1, 2]).
The text delta if this node contains text, otherwise null.
Flutter global key for this node’s widget.
Layer link for overlay positioning.
External values for custom node data.
Temporary data cleared after rendering.
Methods
updateAttributes
void updateAttributes(Attributes attributes)
Updates the node’s attributes by merging with existing attributes.
Attributes to merge into the node.
Example:
node.updateAttributes({'bold': true, 'level': 2});
insert
void insert(Node entry, {int? index})
Inserts a child node at the specified index.
The index to insert at. Defaults to end of children.
insertBefore
void insertBefore(Node entry)
Inserts a node before this node in the parent’s children.
insertAfter
void insertAfter(Node entry)
Inserts a node after this node in the parent’s children.
unlink
Removes this node from its parent’s children.
Returns: true if successful, false if the node has no parent.
childAtPath
Node? childAtPath(Path path)
Returns the descendant node at the relative path.
Relative path from this node.
Returns: The node at the path, or null.
Example:
final child = node.childAtPath([0]); // First child
final grandchild = node.childAtPath([0, 1]); // Second child of first child
childAtIndexOrNull
Node? childAtIndexOrNull(int index)
Returns the child at the given index, or null if out of bounds.
copyWith
Node copyWith({
String? type,
Iterable<Node>? children,
Attributes? attributes,
})
Creates a deep copy of the node with optional overrides.
Returns: A new node with a new ID.
deepCopy
Creates a deep copy of the node including all children.
toJson
Map<String, Object> toJson()
Serializes the node to JSON format.
Example:
final json = node.toJson();
// {
// 'type': 'paragraph',
// 'data': {'delta': [...]},
// 'children': [...]
// }
notify
Manually triggers a rebuild of this node’s widget.
checkDocumentIntegrity
void checkDocumentIntegrity()
Validates document tree integrity (for debugging).
Example
import 'package:appflowy_editor/appflowy_editor.dart';
// Create a paragraph node
final paragraph = Node(
type: 'paragraph',
attributes: {
'delta': Delta([TextInsert('Hello, World!')]).toJson(),
},
);
// Create a heading node with children
final heading = Node(
type: 'heading',
attributes: {
'level': 1,
'delta': Delta([TextInsert('Title')]).toJson(),
},
children: [paragraph],
);
// Access properties
print(heading.type); // 'heading'
print(heading.path); // [0] (if at root)
print(heading.children.length); // 1
// Get the delta
final delta = heading.delta;
if (delta != null) {
print(delta.toPlainText()); // 'Title'
}
// Update attributes
heading.updateAttributes({'level': 2});
// Navigate children
final firstChild = heading.childAtIndexOrNull(0);
final nodeAtPath = heading.childAtPath([0]);
// Copy the node
final copy = heading.copyWith();
// Serialize to JSON
final json = heading.toJson();
final fromJson = Node.fromJson(json);
Common Node Types
paragraph - Text paragraph
heading - Heading with level 1-6
bulletedList - Bulleted list item
numberedList - Numbered list item
todoList - Todo list item
quote - Block quote
code - Code block
divider - Horizontal divider
image - Image block
page - Root page node
See Also