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/Dart convert a string formated as an object into a array

I am attempting to convert a string that is formatted as an object but with no luck, the data is originally formatted as a _CompactLinkedHashSet<String> so i tried to convert it to a json thinking that an array will be the output, below is my code.

var items = dataColumn[index]['items'];
final item = json.decode(json.encode(items.toString()));

When i print(items.runtimeType) the items is equals to _CompactLinkedHashSet<String>
but manage to convert it to a string using json encode and decode but the output is not an array its a string formatted as below

{'Word-1', 'Word-2', 'Word-3'}

I would like to convert it to an array so i can display it inside a ListView.builder like below

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

['Word-1', 'Word-2', 'Word-3']

>Solution :

You can change like below.

enter image description here

void main() {
  var item = {'Word-1', 'Word-2', 'Word-3'};
  print(item.runtimeType);
  print(item);
  
  // var itemList = item.map((item) => item).toList();
  var itemList = List.from(item);
  
  print(itemList.runtimeType);
  print(itemList);
}
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