RichTextController class

a custom controller based on TextEditingController used to activly style input text based on regex patterns and word matching with some custom features. {@tool snippet}

class _ExampleState extends State<Example> {

  late RichTextController _controller;

_controller = RichTextController(
      deleteOnBack: true,
      patternMatchMap: {
        //Returns every Hashtag with red color
        RegExp(r"\B#[a-zA-Z0-9]+\b"):
            const TextStyle(color: Colors.red, fontSize: 22.0),
        //Returns every Mention with blue color and bold style.
        RegExp(r"\B@[a-zA-Z0-9]+\b"): const TextStyle(
          fontWeight: FontWeight.w800,
          color: Colors.blue,
        ),
      },
      regExpCaseSensitive: false,
);

 TextFormField(
 controller: _controller,
 ...
)

{@end-tool}

Inheritance

Constructors

RichTextController({String? text, Map<RegExp, TextStyle>? patternMatchMap, Map<String, TextStyle>? stringMatchMap, required dynamic onMatch(List<String> match), dynamic onMatchIndex(List<Map<String, List<int>>>)?, bool? deleteOnBack = false, bool regExpCaseSensitive = true, bool regExpDotAll = false, bool regExpMultiLine = false, bool regExpUnicode = false})

Properties

deleteOnBack bool?
final
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
onMatch → dynamic Function(List<String> match)
final
onMatchIndex → (dynamic Function(List<Map<String, List<int>>>)?)
final
patternMatchMap Map<RegExp, TextStyle>?
final
regExpCaseSensitive bool
controls the caseSensitive property of the full RegExp used to pattern match
final
regExpDotAll bool
controls the dotAll property of the full RegExp used to pattern match
final
regExpMultiLine bool
controls the multiLine property of the full RegExp used to pattern match
final
regExpUnicode bool
controls the unicode property of the full RegExp used to pattern match
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selection TextSelection
The currently selected text.
getter/setter pairinherited
stringMatchMap Map<String, TextStyle>?
final
text String
The current string the user is editing.
getter/setter pairinherited-getteroverride-setter
value TextEditingValue
The current value stored in this notifier.
getter/setter pairinherited

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
buildTextSpan({required BuildContext context, TextStyle? style, required bool withComposing}) TextSpan
Builds TextSpan from current editing value.
override
clear() → void
Set the value to empty.
inherited
clearComposing() → void
Set the composing region to an empty range.
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).
inherited
isBack(String current, String last) bool
isSelectionWithinTextBounds(TextSelection selection) bool
Check that the selection is inside of the bounds of text.
inherited
matchValueIndex(Match match) Map<String, List<int>>?
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
toString() String
A string representation of this object.
inherited

Operators

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