Container(
color: Colors.yellow,
child: Center(
child: GestureDetector(
onTap: () {
open = !open;
print(open);
},
child: AnimatedContainer(
color: Colors.white,
duration: Duration(seconds: 2),
curve: Curves.easeInCubic,
width: open ? 200 : 20,
height: open ? 200 : 15,
child: Container(
width: 200,
height: 200,
child: Column(
children: [
Text('heey'),
Text('heey'),
Text('heey'),
],

我正在尝试使用带有Column小部件的AnimatedContainer。我怎样才能在AnimatedContainer中做到这一点?我希望Text()小部件在容器下,并且当AnimatedContainer展开时它会保持这种状态。
试图通过OverflowBox()来实现这一点,但它似乎不工作或可能我在这里做错了什么。
发布于 2021-01-17 13:39:28
使用Exapanded() Widget,您的问题将会得到解决。
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(child: Text('heey')),
Expanded(child: Text('heey')),
Expanded(child: Text('heey')),
],
),发布于 2021-01-17 13:24:38
我已经修改了你的代码,我想你想要这样的东西:
更改:使用在列子小部件中展开
在SetState方法中调用open。
Container(
color: Colors.yellow,
child: Center(
child: GestureDetector(
onTap: () {
setState(() {
open = !open;
});
print(open);
},
child: AnimatedContainer(
color: Colors.white,
duration: Duration(seconds: 2),
curve: Curves.easeInCubic,
width: open ? 200 : 20,
height: open ? 200 : 15,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Spacer(),
Expanded(child: Text('heey')),
Expanded(child: Text('heey')),
Expanded(child: Text('heey')),
],
),
),
),
),
)https://stackoverflow.com/questions/65756557
复制相似问题