VisibleWidgetExtension extension

Extension methods for Widget that provide convenient visibility control functionality.

This extension adds methods to conditionally show or hide widgets based on various conditions. Unlike opacity-based hiding, these methods completely remove the widget from the layout when hidden, replacing it with a SizedBox.shrink.

The extension provides both condition-based visibility (visibleIf, visibleIfNot) and null-checking visibility (visibleIfNull, visibleIfNotNull), plus convenience methods for creating empty space.

Example usage:

Text('Conditional content')
  .visibleIf(user.isLoggedIn)
  .visibleIfNotNull(user.name)
on

Methods

boxShrink() SizedBox

Available on Widget, provided by the VisibleWidgetExtension extension

Returns a SizedBox.shrink that takes up no space.
hide() SizedBox

Available on Widget, provided by the VisibleWidgetExtension extension

Hides the widget by returning a SizedBox.shrink.
invisible() SizedBox

Available on Widget, provided by the VisibleWidgetExtension extension

Makes the widget invisible by returning a SizedBox.shrink.
visibleIf(bool condition) Widget

Available on Widget, provided by the VisibleWidgetExtension extension

Shows the widget if the condition is true, otherwise returns an empty SizedBox.
visibleIfNot(bool condition) Widget

Available on Widget, provided by the VisibleWidgetExtension extension

Shows the widget if the condition is false, otherwise returns an empty SizedBox.
visibleIfNotNull(Object? value) Widget

Available on Widget, provided by the VisibleWidgetExtension extension

Shows the widget if the value is not null, otherwise returns an empty SizedBox.
visibleIfNull(Object? value) Widget

Available on Widget, provided by the VisibleWidgetExtension extension

Shows the widget if the value is null, otherwise returns an empty SizedBox.