我一直试图将景点列表项添加到对象 tripAttractions 列表中,但似乎无法正常工作。如何正确添加这些项目?
class Trip {
String image;
String name;
String location;
List<Attraction> tripAttractions = [];
Trip({this.image , this.name, this.location, this.tripAttractions});
}
final List<Trip> tripList = [
Trip(image: 'test image', name: 'NY Trip', location: 'NY Address', tripAttractions: attractions)];
List<Attraction> attractions = [
Attraction('name', 'address', 'imageURL')];
答案 0 :(得分:1)
由于tripAttractions的类型为List,其中Attraction是一个类,因此您必须使用该对象来访问变量,例如
您将不得不遍历tripAttraction列表并按以下方式访问数据,
tripAttractions[0].name
tripAttractions[0].address
tripAttractions[0].imageURL