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

Error thrown RangeError (index): Invalid value: Only valid value is 0: -1 #18

Closed
Gunnar-Stunnar opened this issue Apr 5, 2021 · 7 comments

Comments

@Gunnar-Stunnar
Copy link

splitedTagsList[splitedTagsList.length - 2].trim().toLowerCase();

This should be "-1" not "-2"

@eyoeldefare
Copy link
Owner

eyoeldefare commented Apr 10, 2021

What version of this package are you running?
The reason I ask you that is so I can reproduce your error in my environment. My understanding is, there is a reason why I have it like that and I have tested everything before. So, for me to debug this, I need your version and the parameters you're using inside the widget.

@ShubhamHande99
Copy link

ShubhamHande99 commented Apr 25, 2021

onChanged: (value) {
var splitedTagsList = value.split(" ");

 // check if the spiltedTagsList length is not equal to 1
    if(splitedTagsList.length!=1){

       var lastLastTag =
        splitedTagsList[splitedTagsList.length - 2].trim().toLowerCase();

        print( splitedTagsList[splitedTagsList.length - 2].trim().toLowerCase());

    if (value.contains(" ")) {
      if (lastLastTag.length > 0) {
        _textEditingController.clear();

        if (!_tagsStringContent.contains(lastLastTag)) {
          widget.onTag(lastLastTag);

          if (!_showPrefixIcon) {
            setState(() {
              _tagsStringContent.add(lastLastTag);
              _showPrefixIcon = true;
            });
          } else {
            setState(() {
              _tagsStringContent.add(lastLastTag);
            });
          }
          this._animateTransition();
        }
      }
    }

    }
    
   
  },

@ShubhamHande99
Copy link

════════ Exception caught by widgets ═══════════════════════════════════════════�[39;49m
�[38;5;244mThe following assertion was thrown while calling onChanged:�[39;49m
ScrollController not attached to any scroll views.
'package:flutter/src/widgets/scroll_controller.dart':
Failed assertion: line 108 pos 12: '_positions.isNotEmpty'

�[38;5;244mWhen the exception was thrown, this was the stack�[39;49m
�[38;5;244m#2 ScrollController.position�[39;49m
�[38;5;248m#3 _TextFieldTagsState._animateTransition�[39;49m
�[38;5;248m#4 _TextFieldTagsState.build.�[39;49m
�[38;5;244m#5 EditableTextState._formatAndSetValue�[39;49m
�[38;5;244m#6 EditableTextState.updateEditingValue�[39;49m
�[38;5;244m...�[39;49m
�[38;5;248m════════════════════════════════════════════════════════════════════════════════�[39;49m

to fix this issue
Wrap your _scrollController inside WidgetsBinding.instance.addPostFrameCallback

void _animateTransition() {
var _pw = _deviceWidth;

WidgetsBinding.instance.addPostFrameCallback((_){
_scrollController.animateTo(
  _pw + _scrollController.position.maxScrollExtent,
  duration: const Duration(seconds: 3),
  curve: Curves.easeOut,
);

});

}

@eyoeldefare
Copy link
Owner

I will ask you what I asked the first guy the same question: what version of this package are you running and the parameters you've used to get the errors. If you can't provide that, I can't help you.

@Gunnar-Stunnar
Copy link
Author

Hi sorry for the late reply, at the time I ran this I was using the latest from Pub.dev

@kherel
Copy link

kherel commented May 4, 2021

#23

@eyoeldefare
Copy link
Owner

Fixed

eyoeldefare added a commit that referenced this issue May 20, 2021
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

4 participants