Skip to content

How to set a max character limit? #860

Answered by Arenukvern
faizanje asked this question in Mobile
Discussion options

You must be logged in to vote

I managed to solve it by attaching listener and changing the document the following way:

in initState for example:

widget.quillController.document.changes.listen(_onDocumentChange)

somewhere in class:

void _onDocumentChange(Tuple3<quill.Delta, quill.Delta, quill.ChangeSource> tuple) {
    final documentLength = widget.quillController.document.length;
    if (documentLength > widget.limit) {
      final latestIndex = widget.limit - 1;
      widget.quillController.replaceText(
        latestIndex,
        documentLength - widget.limit,
        '',
        TextSelection.collapsed(offset: latestIndex),
      );
    }
 }

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@singerdmx
Comment options

Answer selected by singerdmx
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Mobile
Labels
None yet
4 participants