SmartEditorController class

The public controller for SmartEditor.

Create an instance and pass it to SmartEditor. Use it to programmatically get/set content, apply formatting, manage undo/redo, and more.

final controller = SmartEditorController();

// Get HTML
String html = await controller.getText();

// Set HTML
controller.setText('<p>Hello <b>World</b></p>');
Inheritance

Constructors

SmartEditorController({bool processInputHtml = true, bool processOutputHtml = true, bool processNewLineAsBr = false})

Properties

canCopy → bool
Whether there is a selection available to copy.
no setter
canPaste → bool
Whether the system clipboard contains pasteable content.
no setter
canRedo → bool
Whether there are actions to redo.
no setter
canUndo → bool
Whether there are actions to undo.
no setter
characterCount → int
Returns the current character count.
no setter
cursorOffset → int?
Current cursor offset in the focused block (0-based document offset).
no setter
document → Document
The current document
no setter
documentController → DocumentController
The internal document controller
no setter
focusedTableInfo → ({int blockIndex, int col, int row})?
Returns info about the currently focused table cell, or null.
no setter
hashCode → int
The hash code for this object.
no setterinherited
hasListeners → bool
Whether any listeners are currently registered.
no setterinherited
imagePickerDelegate ↔ Future<String?> Function()?
Delegate function to pick an image from device files or gallery. Should return the image as a base64 Data URL or file/network URL, or null if cancelled.
getter/setter pair
isDisabled → bool
Whether the editor is currently disabled.
no setter
isInsideTable → bool
Whether the cursor is currently inside a table cell.
no setter
onMessage ↔ void Function(String message)?
Callback for providing user feedback (e.g., SnackBars).
getter/setter pair
onTagSerialize ↔ String? Function(SmartTagType type, String tag, Map<String, String> attributes, Map<String, String> styles, String content)?
Custom tag serialization callback.
getter/setter pair
processInputHtml → bool
final
processNewLineAsBr → bool
final
processOutputHtml → bool
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
searchState → SearchState
Current find and replace state.
no setter
searchStateNotifier → ValueNotifier<SearchState>
Notifier exposing the current state of the Find & Replace overlay and matches.
final
selection → TextSelection?
Current selection in the focused block.
no setter

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
applyFormat(SmartButtonType format, dynamic value) → void
Applies a specific format to the current selection.
attachEditor(SmartEditorWidgetState editor) → void
Register the editor widget (called internally by SmartEditor)
attachToolbar(SmartToolbarState toolbar) → void
Register the toolbar widget (called internally by SmartEditor)
clear() → void
Clears all content from the editor.
clearFocus() → void
Clears focus from the editor.
clearFormatting() → void
Clears formatting on the current selection.
copySelection() → Future<void>
Copies the current selection to the system clipboard as HTML and Text.
deleteColumn() → void
Removes the column at the currently focused cell.
deleteRow() → void
Removes the row at the currently focused cell.
deleteTable() → void
Deletes the entire table at the currently focused block.
disable() → void
Disables the editor (read-only mode).
dispose() → void
Discards any resources used by the object.
override
enable() → void
Enables the editor for editing.
findNext() → void
Navigates to the next search match.
findPrevious() → void
Navigates to the previous search match.
getImageNode(int blockIndex) → ImageNode?
Gets the ImageNode at blockIndex, or null if not an image.
getLinkInfo({int? blockIndex, TextSelection? selection}) → Map<String, String?>
Returns existing link text and url for the current or specified selection.
getText() → Future<String>
Gets the HTML content from the editor.
hideFindReplace() → void
Closes the Find & Replace bar and clears match highlights.
hideLinkTooltip() → void
Closes any active link preview tooltip overlay.
insertColumn() → void
Inserts a column to the right of the currently focused cell.
insertHtml(String html) → void
Inserts HTML at the current cursor position. Parses the HTML and inserts the resulting text content.
insertImage({required String src, String? alt, double? width, double? height, String? caption, SmartTextAlign alignment = SmartTextAlign.center, int? blockIndex}) → int
Inserts an image block at or after blockIndex.
Inserts or applies a hyperlink. If selection is a non-empty range, applies the link to the selection, or replaces the selected text if displayText was modified. If selection is collapsed, inserts a new link span at the cursor.
insertRow() → void
Inserts a row below the currently focused cell.
insertTable({int rows = 2, int cols = 2}) → void
Inserts a new table after the currently focused block.
insertText(String text) → void
Inserts plain text at the current cursor position.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
pasteContent() → Future<void>
Pastes content from the system clipboard into the editor.
redo() → void
Redoes the last undone action.
removeImage(int blockIndex) → void
Removes an image block at blockIndex.
Removes the hyperlink from the current selection or active link span.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
replaceAll() → int
Replaces all found occurrences across the document in a single atomic undo step. Returns the number of occurrences replaced.
replaceCurrent() → void
Replaces the currently focused match with SearchState.replaceText.
setAlignment(SmartTextAlign alignment) → void
Sets alignment on the current block or table cell.
setBlockType(BlockType type) → void
Changes the current block to a specific heading level (1-6) or back to paragraph.
setCursorPosition(int blockIndex, int docOffset, {int? row, int? col}) → void
Sets cursor position in the specified block using 0-based document offset.
setFocus() → void
Sets focus to the editor.
setHint(String text) → void
Sets the hint/placeholder text.
setImageAlignment(int blockIndex, SmartTextAlign alignment) → void
Sets alignment of an image block at blockIndex.
setImageSize(int blockIndex, {double? width, double? height}) → void
Sets size of an image block at blockIndex.
setReplaceExpanded(bool expanded) → void
Expands or collapses the Replace row in the overlay.
setReplaceText(String text) → void
Sets the replacement text.
setSearchOptions(SearchOptions options) → void
Updates the active search options and refreshes matches.
setSearchQuery(String query) → void
Sets the active search query and searches the document.
setSelection(int blockIndex, int startOffset, int endOffset, {int? row, int? col}) → void
Sets text selection in the specified block using 0-based document offsets.
setText(String html) → void
Sets the editor content from an HTML string.
showFindReplace({bool showReplace = false}) → void
Shows the Find (or Find & Replace) floating bar.
toggleBold() → void
Toggles bold on the current selection.
toggleItalic() → void
Toggles italic on the current selection.
toggleStrikethrough() → void
Toggles strikethrough on the current selection.
toggleUnderline() → void
Toggles underline on the current selection.
toString() → String
A string representation of this object.
inherited
undo() → void
Undoes the last action.
updateImage(int blockIndex, {String? src, String? alt, double? width, double? height, String? caption, SmartTextAlign? alignment}) → void
Updates properties on an existing image block at blockIndex.

Operators

operator ==(Object other) → bool
The equality operator.
inherited