initsString function

List<String>? initsString(
  1. String s
)

Returns a List of Strings by adding one character at a time.

Implementation

List<String>? initsString(String s) {
  if (s.isEmpty) {
    return [''];
  }

  List<String> result = [''];
  List<int> codes = s.codeUnits;
  for (int i = 0; i < codes.length; i++) {
    result.add(String.fromCharCodes(codes.sublist(0, i + 1)));
  }
  return result;
}