我想根据孩子的身高来动画化容器的高度,可以吗?
请看下面的例子。卡片>列>容器,动画容器
如何在AnimatedContainer上设置XYZ值以匹配子部件的高度,或者重置父部件。
Widget example(){
return Card(
margin: EdgeInsets.symmetric(horizontal: 10, vertical: 3),
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Column(
children: <Widget>[
Container(
height: 400,
child: Text('Something with height 400'),
),
AnimatedContainer(
duration: Duration(seconds: 2),
width: selected ? xyz : 100.0,
height: selected ? xyz : 100.0,
color: selected ? Colors.red : Colors.blue,
alignment: selected ? Alignment.center : AlignmentDirectional.topCenter,
curve: Curves.fastOutSlowIn,
child: FlutterLogo(size: 75),
),
]
)
}发布于 2020-01-15 05:52:49
您似乎缺少的是使用setState进行颤动重新渲染和启动动画:
AnimatedContainer(
duration: Duration(seconds: 2),
width: selected ? xyz : 100.0,
height: selected ? xyz : 100.0,
color: selected ? Colors.red : Colors.blue,
alignment: selected ? Alignment.center : AlignmentDirectional.topCenter,
curve: Curves.fastOutSlowIn,
child: FlutterLogo(size: 75),
),
RaisedButton(
child: Text('Change dimensions'),
onPressed: (){
setState(() {
selected = !selected;
});
},
),https://stackoverflow.com/questions/59741640
复制相似问题