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
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
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

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.
getText() Future<String>
Gets the HTML content from the editor.
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.
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.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
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.
setFocus() → void
Sets focus to the editor.
setHint(String text) → void
Sets the hint/placeholder text.
setText(String html) → void
Sets the editor content from an HTML string.
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.

Operators

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