Ahmed Wagdi
Ahmed Wagdi

Reputation: 4421

Flutter String.contains(substring) fails when there is a space

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

Answers (1)

farouk osama
farouk osama

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

Related Questions