Reputation: 4421
Using String.contains(substring) to generate a list out of another fails when there is a space in my input.
Here is my code :
List<String> finalSuggestions = suggestions.where((i) => i.contains(new RegExp(pattern,caseSensitive:false, unicode: true))).toList();
As suggestions
is a list of strings, and pattern
is the user input. everything works fine unless the users adds a space in the string he is typing . finalSuggesions
becomes null. else .. as long as the pattern
is only a single word it is all fine.
Upvotes: 1
Views: 822
Reputation: 2539
you don't need to use RegExp
, Because pattern
a string and suggestions
a list of String.
List<String> finalSuggestions = suggestions.where((i) => i.contains(pattern)).toList();
It shouldn't be affected by space in this case
Upvotes: 1