Home > Software design >  Flutter String Concatenation breaking when last string is file extension
Flutter String Concatenation breaking when last string is file extension

Time:07-21

I'm trying to concatenate some strings which will eventually be part of a URL, but the result of the concatenation is always missing the last String which is a file extension.

I've tried all the official ways of concatenating. Here is my latest attempt when I tried to merge the strings by using the join method on a String List.

      String? resColor = color?.label;
      String? resCategory = category?.label;

      print(resColor!.length);
      List<String> refSplit = [
        'previewAssets/',
        resCategory!,
        '/',
        resColor!,
        '.jpg'
      ];

      for (int i = 0; i < refSplit.length; i  ) {
        print(refSplit[i]);
      }
      String ref = refSplit.join('');
      print(refSplit);
      print(ref);

My excepted outcome is obviously that ref would contain all items from refSplit. But it doesn't.

Here is the output from the prints: preview

Try to restart your IDE and try again.

  • Related