TolyCollapse class

A widget that cross-fades between two given children and animates itself between their sizes.

The animation is controlled through the crossFadeState parameter. firstCurve and opacityCurve represent the opacity curves of the two children. The firstCurve is inverted, i.e. it fades out when providing a growing curve like Curves.linear. The sizeCurve is the curve used to animate between the size of the fading-out child and the size of the fading-in child.

This widget is intended to be used to fade a pair of widgets with the same width. In the case where the two children have different heights, the animation crops overflowing children during the animation by aligning their top edge, which means that the bottom will be clipped.

The animation is automatically triggered when an existing TolyCollapse is rebuilt with a different value for the crossFadeState property.

{@tool snippet}

This code fades between two representations of the Flutter logo. It depends on a boolean field _first; when _first is true, the first logo is shown, otherwise the second logo is shown. When the field changes state, the TolyCollapse widget cross-fades between the two forms of the logo over three seconds.

AnimatedCrossFade(
  duration: const Duration(seconds: 3),
  firstChild: const FlutterLogo(style: FlutterLogoStyle.horizontal, size: 100.0),
  secondChild: const FlutterLogo(style: FlutterLogoStyle.stacked, size: 100.0),
  crossFadeState: _first ? CrossFadeState.showFirst : CrossFadeState.showSecond,
)

{@end-tool}

See also:

  • AnimatedOpacity, which fades between nothing and a single child.
  • AnimatedSwitcher, which switches out a child for a new one with a customizable transition, supporting multiple cross-fades at once.
  • AnimatedSize, the lower-level widget which TolyCollapse uses to automatically change size.
Inheritance

Constructors

TolyCollapse({Key? key, required Widget content, Widget? title, Curve opacityCurve = Curves.linear, Curve sizeCurve = Curves.linear, AlignmentGeometry alignment = Alignment.topCenter, EdgeInsetsGeometry titlePadding = const EdgeInsets.symmetric(vertical: 12.0), EdgeInsetsGeometry contentPadding = const EdgeInsets.only(top: 0, right: 8, left: 8, bottom: 8), required Duration duration, Duration? reverseDuration, AnimatedTitleBuilder? titleBuilder, CollapseController? controller, VoidCallback? onOpen, VoidCallback? onClose, bool excludeBottomFocus = true})
Creates a cross-fade animation widget.
const

Properties

alignment AlignmentGeometry
How the children should be aligned while the size is animating.
final
content Widget
final
contentPadding EdgeInsetsGeometry
final
controller CollapseController?
final
duration Duration
The duration of the whole orchestrated animation.
final
excludeBottomFocus bool
When true, this is equivalent to wrapping the bottom widget with an ExcludeFocus widget while it is at the bottom of the cross-fade stack.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onClose VoidCallback?
final
onOpen VoidCallback?
final
opacityCurve Curve
The fade curve of the second child.
final
reverseDuration Duration?
The duration of the whole orchestrated animation when running in reverse.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sizeCurve Curve
The curve of the animation between the two children's sizes.
final
title Widget?
final
titleBuilder AnimatedTitleBuilder?
final
titlePadding EdgeInsetsGeometry
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<TolyCollapse>
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.
override
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}) 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