【发布时间】:2022-01-05 20:08:53
【问题描述】:
我有一个名为 Place 的模型类,并有一个基于模型类的 place 列表。我使用 Navigator.push 并从那里传递 int 数据。现在如何访问 id 与给定 id 号相同的特定地点列表?
这是我的模型类和列表:
class Place {
int id;
String cardImage;
String placeName;
String location;
String country;
String details;
Place({
required this.id,
required this.cardImage,
required this.placeName,
required this.location,
required this.country,
required this.details,
});
}
final List<Place> place = [
Place(
id: 1,
cardImage:
"https://image1_url.jpg",
placeName: "Essence Of Japan",
location: "Tokyo",
country: "Japan",
details: "long text"),
Place(
id: 2,
cardImage:
"https://image2_url.jpg",
placeName: "Essence Of Japan",
location: "Tokyo",
country: "Japan",
details: "long text"),
];
这是我的导航器,其中 pass id 为 1:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailsPage(1),
),
);
现在我想访问下面 id:1 的项目
Place(
id: 1,
cardImage:
"https://image1_url.jpg",
placeName: "Essence Of Japan",
location: "Tokyo",
country: "Japan",
details: "long text"
),
【问题讨论】:
标签: flutter dart flutter-layout flutter-listview