Why in dart in my Cubit LoadedState does code not execute and get skipped?

Viewed 48

I have a LoadedState that runs in my cubit perfectly, until I try and filter the data it is about to display, as it doesn't run that code at all! It skips all the for loop and goes straight to return.

 else if (state is LoadedState) {
            var matches = state.matches;

            for (var i = widget.selectedFilters.length; i < widget.selectedFilters.length; i++) {
              print("111");
              if (matches[i].leagueNumber == widget.selectedFilters[i]) {
                print("222");
                matches.removeAt(i);
              }
            }
            print("333");

            return Container(

The output in the logs is just 333.

Does anybody know why this is? Thanks

1 Answers

The issue is related to your for loop. You're starting the index from widget.selectedFilters.length already. It won't be like this. I assume that you need to start it from 0.

for (var i = 0; i < widget.selectedFilters.length; i++) {
         print("111");
         if (matches[i].leagueNumber == widget.selectedFilters[i]) {
            print("222")
            matches.removeAt(i);
          }
      }

Related