Here is my code:
onPressed: () {
link = links[sessName.indexOf(str, 0)];
print('$link.txt');
},
sessName – links array. For example, I will give the first element: 'http://lingvostim.com/LS2018/about'
I need to add a '.txt'
to the end of link
. I don’t know why string interpolation isn’t working. The console displays only 'http://lingvostim.com/LS2018/about'
. I will be glad of your help.
3
Answers
If you try to print your value
'http://lingvostim.com/LS2018/about'
directly, it should work fine. Just make sure yourlinks[sessName.indexOf(str, 0)]
expression returns expected value.You should add null-aware operator ‘??’ to assign an empty string to the link variable if index not found. That is code after adding null-aware operator. Also you must define if link variable is String.
Use parentheses with dollar for concatenation
onPressed: () {
link = links[sessName.indexOf(str, 0)]??';
print('${link}.txt');
}