通常使用List渲染,写法如下:
Widget _medicPlanDisplayContent(BuildContext context, PlanModels planModels) {
return Container(
child: Column(
children: planModels.plan.map((planModel) {
return _medicPlanDisplayItem(context, planModels, planModel);
}).toList(),
),
);
}
但是当需要同时获取index和element的时候,Flutter就比较麻烦了,如下:
Flex(
direction: Axis.horizontal,
children: visitTimeInfoBean.videoAppointmentList
.asMap()
.map((index, element) =>
MapEntry(index, _voiceVideoInfoItem(index, element)))
.values
.toList()),
还是kotlin比较爽,哈哈
for ((index, value) in array.withIndex()) {
println("the element at $index is $value")
}