如果在遍历List时,需要对特定的列表项进行一些操作时就可以使用List.asMap().entries.map((entrie) {...})来获取索引值
而entrie.key就是索引值
示例:
......
Expanded(
flex: 1,
child: SizedBox(
height: ScreenAdapter.height(738),
child: Obx(()=>Column(
children: controller.sellingPlist.asMap().entries.map((entrie){
// entrie.key 就是索引值
var value=entrie.value;
var picUrl="https://xxx.xxx.com/${value.pic}";
return Expanded(
flex: 1,
child: Container(
color: const Color.fromRGBO(246, 246, 246, 1),
//例如这里要让索引值为2的列表项的margin值为0,而其他为20
margin: EdgeInsets.fromLTRB(0, 0, 0, entrie.key==2?0:ScreenAdapter.height(20)),
child: Row(
children: [
Expanded(
flex: 3,
child: Column(
children: [
SizedBox(
height: ScreenAdapter.height(20)),
Text("${value.title}",
style: TextStyle(
fontSize:
ScreenAdapter.fontSize(38),
fontWeight: FontWeight.bold)),
SizedBox(
height: ScreenAdapter.height(20)),
Text("${value.subTitle}",
style: TextStyle(
fontSize:
ScreenAdapter.fontSize(
28))),
SizedBox(
height: ScreenAdapter.height(20)),
Text("¥${value.price}元",
style: TextStyle(
fontSize:
ScreenAdapter.fontSize(34)))
],
),
),
Expanded(
flex: 2,
child: Padding(
padding: EdgeInsets.all(
ScreenAdapter.height(8)),
child: Image.network(
picUrl.replaceAll("\\", "/"),
fit: BoxFit.cover),
),
)
],
),
));
}).toList()
)),
)),
],
),
)