Flutter 使用颤振在堆栈中构建两个动画列表
我有两个动画列表,每一个都有一定的功能。第一个构建CheckBoxTile,第二个构建ListTile。当我将它们都包装在一个堆栈中时,我发现只有最后的列表在功能方面起作用。因此,它们都会出现在屏幕上,但只有最后一个会使用SetState()更新UI。好像颤振无法识别第一个的功能。这是我的书堆Flutter 使用颤振在堆栈中构建两个动画列表,flutter,dart,Flutter,Dart,我有两个动画列表,每一个都有一定的功能。第一个构建CheckBoxTile,第二个构建ListTile。当我将它们都包装在一个堆栈中时,我发现只有最后的列表在功能方面起作用。因此,它们都会出现在屏幕上,但只有最后一个会使用SetState()更新UI。好像颤振无法识别第一个的功能。这是我的书堆 Stack(children: [ AnimatedList( scrollDirection: Axis.vertical
Stack(children: [
AnimatedList(
scrollDirection: Axis.vertical,
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
key: _listKeyCheckBox,
initialItemCount: workoutsMap
.workoutsMap[value]['$muscleName'].length,
itemBuilder: (context, index, animation) {
return Container(
height: 50,
child: GestureDetector(
onTap: (){
setState(() {
val = true;
});
},
child: CheckboxListTile(
value: val,
onChanged: (changedValue) {
setState(() {
val = changedValue;
});
},
),
),
);
}),
AnimatedList(
scrollDirection: Axis.vertical,
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
key: _listKey,
initialItemCount: workoutObjects.length,
itemBuilder: (context, index, animation) {
return GestureDetector(
onTap: () {
_checkWidgets(index);
setState(() {});
},
child: SlideTransition(
child: workoutObjects[index],
position: animation.drive(_offset),
),
);
},
)
]),
正如您看到的,CheckBoxListTile的第一个动画列表不会更新val,因此UI也不会更新