The editor's visual appearance is controlled by two main components:
EditorStyle: Controls global editor properties such as padding, cursor color, selection color, and TextStyleConfiguration (styles for normal text, bold, href, and code). It also supports a textSpanDecorator for custom logic when rendering text spans (e.g., adding tap recognizers to links).
BlockComponentConfiguration: Used within block builders to define block-specific styles like padding and textStyle based on the block type. This is passed to specific block builders (like HeadingBlockComponentBuilder or TodoListBlockComponentBuilder).
To apply a custom theme, pass your EditorStyle to the editorStyle parameter and your custom map of builders to the blockComponentBuilders parameter in the AppFlowyEditor widget.
// Define global styles
EditorStyle customizeEditorStyle() {
return EditorStyle(
padding: const EdgeInsets.symmetric(horizontal: 20),
cursorColor: Colors.green,
selectionColor: Colors.green,
textStyleConfiguration: TextStyleConfiguration(
text: const TextStyle(fontSize: 18.0, color: Colors.white54),
bold: const TextStyle(fontWeight: FontWeight.w900),
href: const TextStyle(color: Colors.amber),
code: const TextStyle(fontSize: 14.0, color: Colors.blue),
),
);
}
// Define block-specific styles and builders
Map<String, BlockComponentBuilder> customBuilder() {
final configuration = BlockComponentConfiguration(
padding: (node) => const EdgeInsets.symmetric(vertical: 10),
textStyle: (node) => const TextStyle(color: Colors.yellow),
);
return {
...standardBlockComponentBuilderMap,
HeadingBlockKeys.type: HeadingBlockComponentBuilder(configuration: configuration),
TodoListBlockKeys.type: TodoListBlockComponentBuilder(
configuration: configuration,
iconBuilder: (context, node) => Icon(Icons.check_box),
),
};
}
// Apply to the editor
AppFlowyEditor(
editorState: EditorState.blank(),
editorStyle: customizeEditorStyle(),
blockComponentBuilders: customBuilder(),
)