【发布时间】:2022-01-11 17:14:17
【问题描述】:
我在一个页面上从第三方 API 获取数据列表并在另一个页面上使用相同的数据,但我不知道如何使列表可迭代以访问 Widget Build() 方法中的索引。
在此页面上,我正在获取列表。
class DetailsPage extends StatefulWidget {
List<MarkersOnMap> propertydetails;
DetailsPage({Key key, this.propertydetails})
: super(
key: key,
);
@override
_DetailsPageState createState() => _DetailsPageState();
}
这是一个 Build() 方法,我想在每次调用时将索引作为变量访问,目前我只是使用索引 [0]
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
return Scaffold(
appBar: AppBar(
title: Text(widget.propertydetails[0].ePropertiesCardsList.name,
style: appBarTextStyle),
),
bottomNavigationBar: Material(
child: Container(
child: Row(
children: <Widget>[
Row(
children: [
Text(
widget.propertydetails[0].ePropertiesCardsList.price
.toString(),
style: blackBigBoldTextStyle,
),
Text(
widget.propertydetails[0].ePropertiesCardsList.status,
style: blackSmallTextStyle,
),
],
),
child: Container(
child: Text(
'Contact'),
),
),
],
),
),
),
body: ListView(
children: [
Hero(
tag: widget.propertydetails[0].ePropertiesCardsList.name,
child: slider(),
),
titleRating(),
],
),
);
}
从页面发送数据,如下所示
_propertyFinalList(index) {
return Container(
child: Center(
child: InkWell(
onTap: () async {
var get = await future;
if (get.isNotEmpty) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailsPage(
propertydetails: get,
)),
);
}
},
【问题讨论】: