Search filter for words in dart
I have tried make a more optimized version here which also will work for string of any sizes and any number of words:
void main() {
  print(setSearchParam(&quot;Dr apj abdul Kalam&quot;));
  // [D, Dr, a, ap, apj, a, ab, abd, abdu, abdul, K, Ka, Kal, Kala, Kalam]

  print(searchParamWord('test'));
}

List&lt;String&gt; setSearchParam(String caseNumber) =&gt;
    caseNumber.split(' ').expand(searchParamWord).toList();

Iterable&lt;String&gt; searchParamWord(String word) sync* {
  final sb = StringBuffer();

  for (var i = 0; i &lt; word.length; i++) {
    yield (sb..writeCharCode(word.codeUnitAt(i))).toString();
  }
}

I have split the logic of your code into two parts.
searchParamWord takes one word and split it into its components like &quot;(t, te, tes, test)&quot; and returns a lazy evaluated iterator. This iterator can then later be used by expand in setSearchParam where we split the long String into each separate word.
By request, example how to upper case first letter in each word
void main() {
  print(setSearchParam(&quot;Dr apj abdul Kalam&quot;));
  // [D, Dr, A, Ap, Apj, A, Ab, Abd, Abdu, Abdul, K, Ka, Kal, Kala, Kalam]

  print(searchParamWord('test'));
}

List&lt;String&gt; setSearchParam(String caseNumber) =&gt;
    caseNumber.split(' ').expand(searchParamWord).toList();

Iterable&lt;String&gt; searchParamWord(String word) sync* {
  final sb = StringBuffer();

  for (var i = 0; i &lt; word.length; i++) {
    yield (i == 0)
        ? (sb..write(word[i].toUpperCase())).toString()
        : (sb..writeCharCode(word.codeUnitAt(i))).toString();
  }
}