Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter String Concatenation breaking when last string is file extension

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 where 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: output

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Im knida new to flutter but I feel like concatenating strings shouldn’t be this hard, so I’m probably missing something obvious. Any help would be greatly appreciated.

>Solution :

I tried your code and it seems to work fine in dartpad

void main() {
  List<String> refSplit = [
    'previewAssets/',
    'something',
    '/',
    '109',
    '.jpg'
  ];
  String ref = refSplit.join("");
  print(ref);
}

preview

Try to restart your IDE and try again.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading