WordCountService class

A Word Counter service that runs based on the changes and updates to an EditorState.

Due to this service relying on listening to transactions in the Document and iterating the complete Document to count the words and characters, this can be a potential slow and cumbersome task.

To start being notified about updates, run the register method, this will add a listener to the Transaction updates of the EditorState, and do an initial run-through to populate the counter stats.

Mixed in types

Constructors

WordCountService({required EditorState editorState, Duration debounceDuration = const Duration(milliseconds: 300)})

Properties

debounceDuration Duration
The time to wait before input stops, to recalculate word and character count.
final
documentCounters Counters
Number of words and characters in the Document.
no setter
editorState EditorState
final
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
isRunning bool
Signifies whether the service is currently running or not. The service can be stopped/started as needed for performance.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selectionCounters Counters
Number of words and characters in the Selection.
no setter

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
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
getDocumentCounters() Counters
This method can be used to get the word and character count of the Document of the EditorState.
getSelectionCounters() Counters
This method can be used to get the word and character count of the current Selection of the EditorState.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
register() → void
Registers the Word Counter and starts notifying about updates to word and character count.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
stop() → void
Stops the Word Counter and resets the counts.
toString() String
A string representation of this object.
inherited

Operators

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