lixeno1381
lixeno1381

Reputation: 21

How to append two lists in flutter

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"),
    ]),
   );
}

Upvotes: 2

Views: 462

Answers (1)

smotastic
smotastic

Reputation: 398

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

Upvotes: 2

Related Questions