Visibility class

Whether to show or hide a child.

By default, the visible property controls whether the child is included in the subtree or not; when it is not visible, the replacement child (typically a zero-sized box) is included instead.

A variety of flags can be used to tweak exactly how the child is hidden. (Changing the flags dynamically is discouraged, as it can cause the child subtree to be rebuilt, with any state in the subtree being discarded. Typically, only the visible flag is changed dynamically.)

These widgets provide some of the facets of this one:

  • Opacity, which can stop its child from being painted.
  • Offstage, which can stop its child from being laid out or painted.
  • TickerMode, which can stop its child from being animated.
  • ExcludeSemantics, which can hide the child from accessibility tools.
  • IgnorePointer, which can disable touch interactions with the child.

Using this widget is not necessary to hide children. The simplest way to hide a child is just to not include it, or, if a child must be given (e.g. because the parent is a StatelessWidget) then to use SizedBox.shrink instead of the child that would otherwise be included.

See also:



Visibility({Key? key, required Widget child, Widget replacement = const SizedBox.shrink(), bool visible = true, bool maintainState = false, bool maintainAnimation = false, bool maintainSize = false, bool maintainSemantics = false, bool maintainInteractivity = false})
Control whether the given child is visible.
Visibility.maintain({Key? key, required Widget child, bool visible = true})
Control whether the given child is visible.


child Widget
The widget to show or hide, as controlled by visible.
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
maintainAnimation bool
Whether to maintain animations within the child subtree when it is not visible.
maintainInteractivity bool
Whether to allow the widget to be interactive when hidden.
maintainSemantics bool
Whether to maintain the semantics for the widget when it is hidden (e.g. for accessibility).
maintainSize bool
Whether to maintain space for where the widget would have been.
maintainState bool
Whether to maintain the State objects of the child subtree when it is not visible.
replacement Widget
The widget to use when the child is not visible, assuming that none of the maintain flags (in particular, maintainState) are set.
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
visible bool
Switches between showing the child or hiding it.


build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
toString({DiagnosticLevel minLevel =}) String
A string representation of this object.
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
toStringShort() String
A short, textual description of this widget.


operator ==(Object other) bool
The equality operator.

Static Methods

of(BuildContext context) bool
Tells the visibility state of an element in the tree based off its ancestor Visibility elements.