Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] RangeError when selection.isValid is false #11

Closed
MiniSuperDev opened this issue Jun 1, 2023 · 2 comments
Closed

[BUG] RangeError when selection.isValid is false #11

MiniSuperDev opened this issue Jun 1, 2023 · 2 comments

Comments

@MiniSuperDev
Copy link

MiniSuperDev commented Jun 1, 2023

text.substring(0, cursorPosition).lastIndexOf(trigger);

Unhandled Exception: RangeError (end): Invalid value: Not in inclusive range 0..21: -1

When isValid is false baseOffset and other properties are -1

So

AutocompleteQuery? invokingTrigger(TextEditingValue textEditingValue) {
final text = textEditingValue.text;
final cursorPosition = textEditingValue.selection.baseOffset;

I fixed it like this:

  AutocompleteQuery? invokingTrigger(TextEditingValue textEditingValue) {
    if (!textEditingValue.selection.isValid) {
      return null;
    }

    final text = textEditingValue.text;
    final cursorPosition = textEditingValue.selection.baseOffset;

In my case it happens that selection.isValid is false when the Widget is a child of a custom SliverReorderableList and I change its position by drag and drop.

@xsahil03x
Copy link
Owner

Hey @MiniSuperDev, can you also share a small reproducible code which I can test this on?

@xsahil03x
Copy link
Owner

Fixed in 3c1a152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants