DocumentController class
Manages the contents of a DocumentEditor.
Keeps track of the state of its paragraphs and editor:
- SpannedTextEditingController for text
- FocusNode for both text and embeds
- ScrollController for the scroll view of the editor
It also handles creation and deletion of lines based on user actions and ensures a consistent state when editing its controllers or paragraphs.
- Backspace at the start of a line will try to merge it with the previous line.
- Delete at the end of a line tries to merge the next line into the current one.
- newline (\n) cause the line to split; no line may ever contain a newline character.
- There is always a text line at the start and one at the end (before and after any embed paragraphs).
- Inheritance
-
- Object
- ChangeNotifier
- ValueNotifier<
BuiltList< ParagraphState> > - DocumentController
Constructors
-
DocumentController({FocusScopeNode? focusNode, Iterable<
Paragraph> ? paragraphs}) - Create a document controller.
Properties
- focusedLine → LineState?
-
Get the currently focused line. If there is no focused paragraph or the
focusedParagraph is not a LineState this returns null.
no setter
- focusedParagraph → ParagraphState?
-
Get the currently focused paragraph, if any.
no setter
- focusedParagraphIndex → int?
-
Get the index of the focused paragraph or null if no paragraph has focus.
no setter
- focusNode → FocusScopeNode
-
The focus scope node for the controller.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
-
onLineValueChanged
→ Stream<
LineValueChangedEvent> -
Stream of events fired when a text line's TextEditingValue changes.
no setter
-
onParagraphAdded
→ Stream<
ParagraphEvent> -
Stream of events fired when a paragraph is added.
no setter
-
onParagraphRemoved
→ Stream<
ParagraphEvent> -
Stream of events fired when a paragraph is removed.
no setter
-
paragraphs
↔ BuiltList<
ParagraphState> -
Get the paragraphs in this docuent.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
value
↔ BuiltList<
ParagraphState> -
The current value stored in this notifier.
getter/setter pairinherited-setteroverride-getter
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
appendEmbed(
ParagraphEmbed embed) → EmbedState - Add an embed after all existing paragraphs.
-
appendLine(
[LineParagraph? line]) → LineState - Add a line after all existing paragraphs.
-
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener will throw after the object is disposed).
override
-
getAttributeListener(
TextAttribute attribute) → ValueListenable< bool> -
Get a ValueListenable that indicates if
attribute
is applied for the current selection. -
getAttributeTypeListener<
T extends TextAttribute> () → ValueListenable< bool> -
Get a ValueListenable that indicates if an attribute of type
T
is applied for the current selection. -
getModifierListener(
LineModifier modifier) → ValueListenable< bool> -
Get a ValueListenable that indicates if
modifier
is applied for the current line. -
insertEmbed(
int index, ParagraphEmbed embed, {bool deleteLineIfEmpty = true}) → EmbedState -
Insert an embed at
index
. -
insertEmbedAtCurrent(
ParagraphEmbed embed, {bool deleteLineIfEmpty = true}) → EmbedState? - Insert an embed at the current index.
-
insertLine(
int index, [LineParagraph? line]) → LineState -
Insert a line at
index
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
removeCurrentParagraph(
) → void - Remove the focused paragraph.
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
removeParagraphAt(
int index) → void -
Remove the paragraph at
index
. -
setLineStyle(
TextAttribute attribute) → void - Apply a text attribute to the currently focused line, if there is one.
-
setLineStyleAt(
int index, TextAttribute attribute) → void - Apply a text attribute to the line at the given index, if the index is valid and points to a LineState.
-
setLineStyleOf(
LineState line, TextAttribute attribute) → void - Apply a text attribute to the given line. Typically used with attributes with SpanExpandRules.fixed.
-
toDocument(
) → Document - Get the contents of this controller represented as a document.
-
toggleLineModifier(
LineModifier modifier) → void - Toggles a line modifier for the focused line.
-
toggleLineStyle(
TextAttribute attribute) → void - Toggle an attribute for the current line.
-
toString(
) → String -
A string representation of this object.
inherited
-
unsetLineStyle(
TextAttribute attribute) → void - Remove a text attribute from the currently focused line, if there is one.
-
unsetLineStyleAt(
int index, TextAttribute attribute) → void - Remove a text attribute from the line at the given index, if the index is valid and points to a LineState.
-
unsetLineStyleOf(
LineState line, TextAttribute attribute) → void - Remove a text attribute from the currently focused line, if there is one.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited