I am running
list.firstWhere and this is sometimes throwing an exception:
Bad State: No element When the exception was thrown, this was the stack: #0 _ListBase&Object&ListMixin.firstWhere (dart:collection/list.dart:148:5)
I do not understand what this means an also could not identify the issue by looking at the source.
firstWhere looks like this:
list.firstWhere((element) => a == b);
This will happen when there is no matching element, i.e. when
a == b is never true for any of the elements in
list and the optional parameter
orElse is not specified.
You can also specify
orElse to handle the situation:
list.firstWhere((element) => a == b, orElse: () => print('No matching element.'));