AnimatedWidgetStack class

Draws widgets stack. Can use any widgets. Calls widgetChangeBuilder builder to create animated widget and show a transition between old and current stackedWidgets. Each widget of stackedWidgets should contain an unique key.

Example:

class Example extends StatefulWidget {
  const Example({super.key});

  @override
  State<AnimatedExample1Default> createState() => _AnimatedExample1DefaultState();
}

class _AnimatedExample1DefaultState extends State<AnimatedExample1Default> {
  late List<Widget> _stackedWidgets =
      List.generate(5, (index) => index).map((index) => _generateAvatar(index)).toList();

  Widget _generateAvatar(int index) => BorderedCircleAvatar(
        key: _generateKey(index),
        border: const BorderSide(color: Colors.orange, width: 2.0),
        backgroundImage: NetworkImage(getAvatarUrl(index)),
        constraints: const BoxConstraints.expand(),
      );

  Key _generateKey(int index) => Key('BCA_$index');

  Widget _infoItemBuilder(int surplus, BuildContext context) => BorderedCircleAvatar(
        constraints: const BoxConstraints.expand(),
        child: Center(child: Text('+$surplus')),
      );

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 50,
      child: AnimatedWidgetStack(
        positions: RestrictedPositions(maxCoverage: 0.5, minCoverage: 0.3),
        stackedWidgets: _stackedWidgets,
        widgetChangeBuilder: (context, action, constraints) {
          return WidgetWithParameters(
            widget: DefaultAnimatedAction(
              key: action.key,
              action: action,
              size: constraints.biggest,
              infoWidgetBuilder: _infoItemBuilder,
            ),
          );
        },
      ),
    );
  }
}
Inheritance

Constructors

AnimatedWidgetStack({required Positions positions, required List<Widget> stackedWidgets, required WidgetChangeBuilder widgetChangeBuilder, Key? key})
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
positions → Positions
Algorithm of calculating positions
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
stackedWidgets → List<Widget>
List of any widgets to draw Every widget should contain an unique key
final
widgetChangeBuilder → WidgetChangeBuilder
Animated transition builder
final

Methods

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