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
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);
}
Try to restart your IDE and try again.
