Home > Mobile >  Insert String array into list of model in Flutter
Insert String array into list of model in Flutter

Time:01-15

How to insert String array to list object / list model?

My result String array:

[198507282014041001, 199001312019031018, 199112212019031014, 197710232002121001]

I wanna add my string to my model, this my model:

class Tag {
  final String id;

  Tag(this.id);
}

CodePudding user response:

Try the following code:

List<String> stringList = [
  "198507282014041001",
  "199001312019031018",
  "199112212019031014",
  "197710232002121001",
];

List<Tag> tagList = stringList.map((e) => Tag(e)).toList();

print(tagList.map((e) => e.id).toList()); // Check if there is already data in the model
  • Related