希望你安全并且做得很好。好的,所以我的问题是我想使用cardBuilder 的索引
cardBuilder: (context, index) => Card(
在swipeUpdateCallback中,我想在向右或向左滑动时使用它,我该怎么做?如何在 swipeUpdateCallback 中调用索引?
swipeUpdateCallback:
(DragUpdateDetails details, Alignment align) {
if (align.x < 0) {
_dataService.seenPost(
welcomeImages[_index].id, ///want to use the index here///
welcomeImages[_index].seen, ///want to use the index here///
welcomeImages[_index].imgPath); ///want to use the index here///
}
这是小部件的完整代码:
child: new TinderSwapCard(
swipeUp: true,
swipeDown: true,
orientation: AmassOrientation.BOTTOM,
totalNum: welcomeImages.length,
stackNum: 3,
swipeEdge: 4.0,
maxWidth: MediaQuery.of(context).size.width * 1.5,
maxHeight: MediaQuery.of(context).size.width * 1.5,
minWidth: MediaQuery.of(context).size.width * 1.4,
minHeight: MediaQuery.of(context).size.width * 1.4,
cardBuilder: (context, index) => Card( ///Here's the index i want to use///
child: SingleChildScrollView(
child: Column(
children: [
Text('s'),
new Image.network(
'${welcomeImages[index].imgPath}',
fit: BoxFit.cover,
),
],
),
),
),
cardController: controller = CardController(),
swipeUpdateCallback:
(DragUpdateDetails details, Alignment align) {
if (align.x < 0) {
_dataService.seenPost(
welcomeImages[index].id, ///want to use the index here///
welcomeImages[index].seen,
welcomeImages[index].imgPath);
} else if (align.x > 0) {
//Card is RIGHT swiping
}
},