简体   繁体   中英

Concatenate list of strings into single string

I am new in flutter I want to know how can i concatenate the list of strings into a single string. I tried to do phrase.toString(). i have also tried

But I am not getting the required result. How can I get the concatenation of only tags of the list? Any help will be appreciated.

List phrase = [
      {
        'tag': 'This is a flutter',
       
      },
      {
        'tag': 'learning session',
        'icon': icon.flutter,
      },
      {
        'tag': 'Therefore,',
        'icon': icon.learningHat,
      },
      {
        'tag': 'Login here',
      },
    ];

I am expecting the out should be: This is a flutter learning session. Therefore login here.

I have tried:

final phraseTags = phrase[index]['tags'];

but not getting the required result

You are having typo on tags will be tag

final phraseTags = phrase[index]['tag'];

Use this method:

getTags(List list) {
 List listOfTagsOnly = list.map((e) => e["tag"].trim()).toList();
  return listOfTagsOnly.join(" ");
}

print(getTags(phrase)); // This is a flutter learning session Therefore, Login here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM