[英]Icons still showing even if it's parent widget's height is zero in Flutter
I have an AnimatedContainer and as it's child, I have a Row containing a Text and an IconButton.我有一个 AnimatedContainer,作为它的孩子,我有一个包含文本和图标按钮的行。 After clicking some button, I am toggling the height of the Container between 0 and 100. When the Container height is zero, the IconButton is still visible (not the Text) and not clickable.
单击某个按钮后,我在 0 和 100 之间切换 Container 的高度。当 Container 高度为零时,IconButton 仍然可见(不是文本)并且不可单击。
Widget _myAnimatedContainer() {
return AnimatedContainer(
curve: Curves.easeOut,
alignment: Alignment.center,
duration: Duration(milliseconds: 300),
height: height,
color: Colors.green,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Text(
'Animated Container',
style: TextStyle(fontSize: 20),
overflow: TextOverflow.ellipsis,
),
IconButton(icon: Icon(Icons.favorite_border), onPressed: () {},)
],
),
);
}
class _AnimatedContainerExampleState extends State<AnimatedContainerExample> {
double height = 100;
bool isExpanded = false;
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
_myAnimatedContainer(),
SizedBox(height: 20,),
RaisedButton(
child: Text('Expand'),
onPressed: () {
setState(() {
isExpanded = !isExpanded;
height = isExpanded ? 100 : 0;
});
},
),
],
),
);
}
Please suggest how to solve this issue.请建议如何解决这个问题。
Add the if condition:添加if条件:
if (height > 0)
IconButton(icon: Icon(Icons.favorite_border), onPressed: () {},)
You might want to use a different value from 0 (like 10) to remove the icon您可能希望使用与 0 不同的值(如 10)来删除图标
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.