Add a new element
Build an extension when your product needs content or actions the included extensions do not provide. An element ships as two packages: a pure-Dart element package and a Flutter _editor package.
Import document_editor_extensions.dart, create your DocumentExtension once, and pass it to the controller's extensions.
Decide what users can do
| Question | Example |
|---|---|
| What does it contain? | Text, child blocks, an image, a custom graphic |
| How is it selected? | Text inside it, the whole object, or both |
| Which properties change? | Color, padding, font size, a frame |
| Where can it appear? | In the flow, inside another element, floating |
| What happens across pages? | Continue, or keep together |
| Which formats save it? | JSON, plus the codecs you contribute |
Expose only the properties and actions the element supports.
Element package
- Definition: the content type, its JSON and where the schema allows it. Attributes must be JSON values; IDs must be unique.
- Commands: extension methods on
DocumentCommandTarget, like the included command APIs. Group related changes in a transaction so they undo together. - Codecs and layout: DOCX, Markdown and HTML contributions, and a layout adapter whose paint PDF and print reuse.
Editor package
- Action IDs: one
enumimplementingEditorActionId(see Typed identifiers). Keep eachkeystable once released; saved settings store it. - Actions for the toolbar and insert menus.
- Properties for the inspector.
- Presentation: block and inline views, menus.
Check the whole experience
Try selection, typing, property changes, clipboard and Undo/Redo. For long content, check page continuation. Open and save a document in every format you contribute.
The extension integration reference has registration details and complete examples.