Notification texts go here Contact Us Buy Now!

Icons still showing even if it's parent widget's height is zero in Flutter

If you've encountered icons still showing even when their parent widget's height is zero in Flutter, there are a few solutions you can explore:

1. Use an if condition:

if (height > 0) {
  IconButton(
    icon: Icon(Icons.favorite_border),
    onPressed: () {},
  )
}

This conditional statement checks if the height of the parent widget is greater than 0. If it is, the IconButton will be displayed; otherwise, it won't. You might need to adjust the value from 0 (e.g., use 10) to ensure the icon is hidden when the parent widget's height is minimal.

2. Clip the parent Container:

Container(
  clipBehavior: Clip.hardEdge,
  height: 0,
  child: IconButton(
    icon: Icon(Icons.favorite_border),
    onPressed: () {},
  )
)

Adding 'clipBehavior: Clip.hardEdge' to the parent Container can resolve the issue. This property prevents the IconButton from overflowing outside the Container's boundaries, effectively hiding it when the Container's height is zero.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.