ControlledVisibility class
A controller-driven wrapper that shows or hides child.
ControlledVisibility owns visibility state, lifecycle, timing, and
reduced-motion behavior without prescribing a visual animation. Supply
showTransition, hideTransition, or both when a direction should be
animated. Each transition receives an animation from 0 (hidden) to 1
(shown).
When a direction's transition is omitted, its controller command changes visibility immediately and the corresponding duration is ignored.
By default, hidden content remains mounted and keeps its layout space, but
cannot receive pointer input and is excluded from semantics. Set unmount
to true to dispose the child after hiding. Showing it again creates a new
element subtree before an optional transition begins.
final controller = VisibilityController();
ControlledVisibility(
controller: controller,
showTransition: (child, animation) => FadeTransition(
opacity: CurveTween(curve: Curves.easeOutCubic).animate(animation),
child: child,
),
hideTransition: (child, animation) => FadeTransition(
opacity: animation,
child: child,
),
child: const Text('Details'),
)
See the ControlledVisibility guide for lifecycle, transition, and unmounting behavior.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- ControlledVisibility
Constructors
-
ControlledVisibility({required VisibilityController controller, required Widget child, Widget showTransition(Widget child, Animation<
double> animation)?, Widget hideTransition(Widget child, Animation<double> animation)?, Duration showDuration = const Duration(milliseconds: 300), Duration hideDuration = const Duration(milliseconds: 300), bool unmount = false, void onShow(Future<void> transition)?, void onHide(Future<void> transition)?, Key? key}) -
Creates a controller-driven visibility wrapper around
child.const
Properties
- child → Widget
-
Widget whose visibility is controlled.
final
- controller → VisibilityController
-
Controller that shows or hides child.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- hideDuration → Duration
-
Duration of the optional transition while hiding child.
final
-
hideTransition
→ Widget Function(Widget child, Animation<
double> animation)? -
Builder for the optional visual transition while hiding child.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
onHide
→ void Function(Future<
void> transition)? -
Callback invoked immediately when a hide operation is requested.
final
-
onShow
→ void Function(Future<
void> transition)? -
Callback invoked immediately when a show operation is requested.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- showDuration → Duration
-
Duration of the optional transition while showing child.
final
-
showTransition
→ Widget Function(Widget child, Animation<
double> animation)? -
Builder for the optional visual transition while showing child.
final
- unmount → bool
-
Whether child is removed from the widget tree after it is hidden.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< ControlledVisibility> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited