【问题标题】:How to append two lists in flutter如何在颤动中附加两个列表
【发布时间】:2021-10-20 03:05:42
【问题描述】:

我已经创建了颤振模型并尝试合并两个列表。请指导我解决这个问题。

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

【问题讨论】:

    标签: android arrays flutter dart dart-pub


    【解决方案1】:

    您可以使用扩展运算符来组合两个列表

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

    另请参阅:https://dart.dev/guides/language/language-tour#spread-operator

    还有https://stackoverflow.com/a/21826420/9479695

    【讨论】:

      猜你喜欢
      • 2021-10-10
      • 1970-01-01
      • 2022-06-28
      • 2020-01-18
      • 2021-10-26
      • 1970-01-01
      • 2020-06-14
      • 1970-01-01
      • 2021-03-23
      相关资源
      最近更新 更多