2

I've already created the flutter model and trying to combine two lists. Please guide me to solve this issue.

class LocationFacts{
  late int id;
  late String title;

  Location(this.id, this.content);
}

class Location{
late String name;
late List<LocationFacts> facts;

  Location(this.name, this.facts);

static List<Location> locationData() {
    return ls = []..add(Location(name: "abc", facts: [
    LocationFacts(id: 1, title: "xyz"),
    LocationFacts(id: 2, title: "qrs"),
    ]),
   );
}
lixeno1381
  • 21
  • 1

1 Answers1

2

You can use the spread operator to combine two lists

final ls = [...list1, ...list2];

See also: https://dart.dev/guides/language/language-tour#spread-operator

And https://stackoverflow.com/a/21826420/9479695

smotastic
  • 388
  • 1
  • 11