List 如何在Flatter中从列表映射堆栈中恢复已删除的数据项
我创建了一堆卡片,List 如何在Flatter中从列表映射堆栈中恢复已删除的数据项,list,flutter,dart,List,Flutter,Dart,我创建了一堆卡片,CardDemo是最上面的卡片,activecard和activecard后面的所有其他卡片都是虚拟卡片。当我刷活动卡时,它将从堆栈中移除。当我按下BottomBar小部件时,我需要将相同的卡放在堆栈顶部。我尝试了一些代码,但没有正常工作,如果有人能帮我解决这个问题,那就太好了 timeDilation = 0.4; double initialBottom = 15.0; var dataLength = data.length;
CardDemo
是最上面的卡片,activecard
和activecard
后面的所有其他卡片都是虚拟卡片。当我刷活动卡时,它将从堆栈中移除。当我按下BottomBar
小部件时,我需要将相同的卡放在堆栈顶部。我尝试了一些代码,但没有正常工作,如果有人能帮我解决这个问题,那就太好了
timeDilation = 0.4;
double initialBottom = 15.0;
var dataLength = data.length;
double backCardPosition = initialBottom + (dataLength - 1) * 10 + 10;
double backCardWidth = -10.0;
bool rewind = false;
int count = 0;
Container(
width: screenWidth(context, dividedBy: 1),
height: screenHeight(context, dividedBy: 1),
color: Constants.kitGradients[31],
child: Stack(
children: [
SingleChildScrollView(
child: new Container(
width: screenWidth(context, dividedBy: 1),
height: screenHeight(context, dividedBy: 1),
color: Constants.kitGradients[31],
//color: new Color.fromRGBO(106, 94, 175, 1.0),
alignment: Alignment.center,
child: rewind == true
? dataLength > 0
? new Stack(
alignment: AlignmentDirectional.center,
children: data.map((item) {
count = data.indexOf(item);
// int pos = data.indexWhere((rewind) => true);
if (count == dataLength - 1) {
return CardDemo(
foodName: item['name'](
rewind == true ? [count - 1] : [count]),
price: item['price'](
rewind == true ? [count - 1] : [count]),
type: item['type'](
rewind == true ? [count - 1] : [count]),
img: item['image'](
rewind == true ? [count - 1] : [count]),
rating: item['rating'](
rewind == true ? [count - 1] : [count]),
hotel: item['hotel'](
rewind == true ? [count - 1] : [count]),
bottom: bottom.value,
right: right.value,
left: 0.0,
cardWidth: backCardWidth + 10,
rotation: rotate.value,
skew: rotate.value < -10 ? 0.1 : 0.0,
dismissImg: dismissImg,
flag: flag,
addImg: addImg,
swipeRight: swipeRight,
swipeLeft: swipeLeft);
} else {
backCardPosition = backCardPosition - 10;
backCardWidth = backCardWidth + 10;
return cardDemoDummy(
item['image'][count],
backCardPosition,
0.0,
0.0,
backCardWidth,
0.0,
0.0,
context);
}
}).toList())
: new Text(
"No Event Left",
style: new TextStyle(
color: Colors.white, fontSize: 50.0),
)
: dataLength > 0
? new Stack(
alignment: AlignmentDirectional.center,
children: data.map((item) {
count = data.indexOf(item);
//int pos = data.indexWhere((rewind) => true);
if (count == dataLength - 1) {
return CardDemo(
foodName: item['name'],
price: item['price'],
type: item['type'],
img: item['image'],
rating: item['rating'],
hotel: item['hotel'],
bottom: bottom.value,
right: right.value,
left: 0.0,
cardWidth: backCardWidth + 10,
rotation: rotate.value,
skew: rotate.value < -10 ? 0.1 : 0.0,
dismissImg: dismissImg,
flag: flag,
addImg: addImg,
swipeRight: swipeRight,
swipeLeft: swipeLeft);
} else {
backCardPosition = backCardPosition - 10;
backCardWidth = backCardWidth + 10;
return cardDemoDummy(
item['image'],
backCardPosition,
0.0,
0.0,
backCardWidth,
0.0,
0.0,
context);
}
}).toList())
: new Text(
"No Event Left",
style: new TextStyle(
color: Colors.white, fontSize: 50.0),
),
),
),
new Positioned(
bottom: 0,
child: BottomBar(
onRewind: () {
setState(() {
rewind = true;
});
},
),
),
],
),
),
时间膨胀=0.4;
双初始底部=15.0;
var dataLength=data.length;
双backCardPosition=初始底部+(数据长度-1)*10+10;
双背面宽度=-10.0;
布尔倒带=假;
整数计数=0;
容器(
宽度:屏幕宽度(上下文,除以:1),
高度:屏幕高度(上下文,除以:1),
颜色:常数。基特梯度[31],
子:堆栈(
儿童:[
SingleChildScrollView(
子容器:新容器(
宽度:屏幕宽度(上下文,除以:1),
高度:屏幕高度(上下文,除以:1),
颜色:常数。基特梯度[31],
//颜色:新颜色。来自RGBO(106,94,175,1.0),
对齐:对齐.center,
子项:倒带==真
?数据长度>0
?新堆栈(
对齐:对齐方向.center,
子项:data.map((项){
计数=数据索引(项目);
//int pos=数据索引,其中((倒带)=>真);
如果(计数==数据长度-1){
返回卡片演示(
食品名称:项目['name'](
倒带==true?[count-1]:[count]),
价格:项目[‘价格’](
倒带==true?[count-1]:[count]),
类型:项目['type'](
倒带==true?[count-1]:[count]),
img:item['image'](
倒带==true?[count-1]:[count]),
评级:项目[“评级”](
倒带==true?[count-1]:[count]),
酒店:项目[“酒店”](
倒带==true?[count-1]:[count]),
bottom:bottom.value,
右:右。值,
左:0.0,
卡片宽度:背面卡片宽度+10,
旋转:rotate.value,
倾斜:旋转。值<-10?0.1:0.0,
解雇,解雇,
国旗:国旗,
addImg:addImg,
swipeRight:swipeRight,
swipeLeft:swipeLeft);
}否则{
backCardPosition=backCardPosition-10;
backCardWidth=backCardWidth+10;
回程卡(
项目['image'][count],
后卫位置,
0.0,
0.0,
背面宽度,
0.0,
0.0,
上下文);
}
}).toList())
:新文本(
“没有剩余事件”,
样式:新文本样式(
颜色:颜色。白色,字体大小:50.0),
)
:dataLength>0
?新堆栈(
对齐:对齐方向.center,
子项:data.map((项){
计数=数据索引(项目);
//int pos=数据索引,其中((倒带)=>真);
如果(计数==数据长度-1){
返回卡片演示(
foodName:item['name'],
价格:项目[‘价格’],
类型:项目['type'],
img:item['image'],
评级:项目[‘评级’],
酒店:项目[“酒店”],
bottom:bottom.value,
右:右。值,
左:0.0,
卡片宽度:背面卡片宽度+10,
旋转:rotate.value,
倾斜:旋转。值<-10?0.1:0.0,
解雇,解雇,
国旗:国旗,
addImg:addImg,
swipeRight:swipeRight,
swipeLeft:swipeLeft);