lexical_flutter library

Flutter rendering for lexical_core.

Lexical's reconciler diffs into a DOM and lets contenteditable handle input and selection. Flutter offers neither, so this layer is designed rather than translated:

  • one render object per block, so a keystroke relayouts a paragraph rather than the document;
  • an InlineSpan and a bidirectional offset map built in the same walk, so they cannot drift apart;
  • rebuilds driven by each commit's dirty set, so untouched blocks are reused by reference.
LexicalDocument(
  editor: editor,
  theme: LexicalTheme(baseTextStyle: DefaultTextStyle.of(context).style),
)

Node types come from their own packages; this one knows only the element and text base shapes, and styles blocks by their type string so it never has to import them.

Classes

BlockCaret
A caret to paint over a block's text.
BlockMarker
A marker rendered before a block's content, such as a bullet or a number.
BlockOffsetMap
The bidirectional map between one block's flat text and its model points.
BlockPoint
A point together with the block that contains it.
BlockRegistry
The blocks currently mounted, keyed by node.
BlockRegistryScope
Makes the BlockRegistry of the enclosing document available to descendants.
BlockSelectionSpan
One block's share of a selection that may cover several.
BlockStyle
Everything a block-level element needs to present itself.
BuiltBlockSpan
The rendered form of one block's inline content.
DocumentSelection
The model's selection, split across the blocks it touches.
EditingWindow
One block's contribution to the platform's editing value.
ForeignSelection
Someone else's range and caret, painted in their own colour.
GridCell
Assigns a GridPlacement to a child of LexicalGrid.
GridPlacement
Where a child sits in a LexicalGrid, and how far it reaches.
LexicalBuilder
Builds a widget from the editor's current state, after every commit.
LexicalDocument
Renders the document held by a LexicalEditor.
LexicalDocumentState
State of a LexicalDocument; exposed so the editable layer can reach the block registry.
LexicalEditable
An editable Lexical document.
LexicalEditableState
State of a LexicalEditable; exposed for caret and selection geometry.
LexicalEditorScope
Makes the LexicalEditor rendering a document available to its subtree.
LexicalGrid
Lays children out in a grid of columnCount equal columns.
LexicalInlineBlock
Renders one block's inline content.
LexicalInput
Owns the platform text-input connection for one editor.
LexicalInteraction
Declares which node types react to the pointer, and what happens when they do.
LexicalInteractionRegion
Turns pointer movement over a document into LexicalInteraction callbacks.
LexicalInteractionRegionState
State of a LexicalInteractionRegion, for feeding in external taps.
LexicalNodeHit
A node under the pointer, with everything needed to act on it.
LexicalRenderStats
Counts how much work a commit caused. Test-only.
LexicalSelectionOverlay
The handles, toolbar and magnifier of one editable.
LexicalTheme
The visual configuration of a rendered document.
MountedBlock
What the input and selection layers need to know about a mounted block.
OffsetSegment
One node's contribution to a block's flat text.
RegisteredBlock
Registers its inline block with the enclosing BlockRegistry while mounted.
RemoteSelection
Someone else's selection, to paint alongside the local one.
RenderLexicalBlock
Lays out and paints the inline content of a single block.
RenderLexicalGrid
The render object behind LexicalGrid.
ResolvedPoint
A resolved position in the document.
SelectionEndpoints
Where the two ends of a selection sit, in global coordinates.
SpanBuilder
Builds spans and offset maps for inline content.
WindowAnchor
Where a previous window sat, so the next one can stay put.

Enums

TabBehaviour
What the Tab key does.

Constants

copyCommand → const LexicalCommand<void>
Copy the selection to the clipboard.
cutCommand → const LexicalCommand<void>
Cut the selection to the clipboard.
defaultWindowRadius → const int
How much text either side of the caret the platform is told about.
imeUpdateTag → const String
Marks an update that came from the platform input method.
inputActionCommand → const LexicalCommand<TextInputAction>
Fired when the platform requests an editing action Flutter models as an input action rather than as text — the return key on a single-line field, for instance.
keyDownCommand → const LexicalCommand<KeyEvent>
A raw key press, before any default handling.
pasteCommand → const LexicalCommand<void>
Paste the clipboard at the selection.
windowRewindowMargin → const int
How close the caret may come to a window edge before the window moves.

Properties

isBuildingWidgets bool
Whether the framework is building widgets at this moment.
no setter

Functions

$buildEditingWindow({WindowAnchor? previous, BlockOffsetMap? reuseOffsets, int radius = defaultWindowRadius, TextRange composing = TextRange.empty}) EditingWindow?
Builds the editing window for the current selection, or null.
$resolveDocumentSelection() DocumentSelection?
Resolves the active selection into per-block spans.
$resolveSelectionSpans(RangeSelection selection) DocumentSelection?
Resolves any pair of points into per-block spans.
applyCaseTransform(String text, int format) String
Applies the case-transform format bits to a rendered string.
buildModelOffsets(ElementNode block) BlockOffsetMap
Builds block's flat text and offset map from the model alone.
defaultCssStyleResolver(String css, TextStyle base) TextStyle
The default resolver: the handful of declarations Lexical's toolbars emit.
defaultLexicalContextMenu(BuildContext context, LexicalEditableState editable) Widget
The platform's own selection menu, with the usual four entries.
flatSelectionFor(BlockSelectionSpan span, BlockOffsetMap offsets) TextSelection?
Converts span into flat offsets against offsets, or null when empty.
hitTestNodes({required BlockRegistry registry, required LexicalEditor editor, required Set<String> types, required Offset globalPosition}) LexicalNodeHit?
The interactive node under globalPosition, or null.
isInlineContent(LexicalNode node) bool
Whether node contributes to an inline run rather than being its own block.
parseCssColor(String? value) Color?
Parses #rgb, #rrggbb, #rrggbbaa, rgb(...) and rgba(...).
parseCssDeclarations(String css) Map<String, String>
Parses a CSS declaration list into property -> value pairs.
parseCssFontWeight(String? value) FontWeight?
Parses a CSS font-weight, numeric or keyword.
parseCssLength(String? value, double? base) double?
Parses a CSS length in px, pt, em or rem into logical pixels.
parseCssTextDecoration(String? value) TextDecoration?
Parses a CSS text-decoration shorthand, keeping only the line values.
whenBuildIsDone(VoidCallback action) → void
Runs action now, or at the end of the frame if a build is in progress.

Typedefs

BlockLayoutBuilder = Widget Function(BuildContext context, ElementNode element, Widget buildChild(LexicalNode node))
Lays out a block whose children are not simply stacked.
BlockMarkerBuilder = BlockMarker? Function(BuildContext context, ElementNode node)
Builds the marker for one block, or returns null for none.
BlockStyleResolver = BlockStyle Function(ElementNode node, BlockStyle base)
Refines a block's presentation using the node itself.
CssStyleResolver = TextStyle Function(String css, TextStyle base)
Resolves a node's raw style string onto a TextStyle.
DecoratorBuilder = Widget Function(BuildContext context, DecoratorNode node)
Renders a decorator node.
LexicalContextMenuBuilder = Widget Function(BuildContext context, LexicalEditableState editable)
Builds the menu shown over a selection.
LexicalNodeHitCallback = void Function(LexicalNodeHit hit)
Called when the pointer enters, leaves or taps an interactive node.
TokenBuilder = Widget Function(BuildContext context, TextNode node, TextStyle style)
Renders a token-mode text node as a widget rather than as text.