build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Builds the transition, uses either buildVerticalTransition, buildDefaultTransition, or buildBidirectionalTransition depending on useVerticalTransition.

This method is only responsible for building the animations that all the transitions use.

Implementation

@override
Widget build(BuildContext context) {
  // Define at which point during the transition the scrim will start to
  // show.
  final scrimAnimationStart = useVerticalTransition
      ? 0.0
      : transitionWidget != null
          ? 0.0
          : 0.2;

  // Define the scrim animation.
  final Animation<Color?> scrimAnimation = ColorTween(
    begin: settings.scrimColor.withOpacity(0.0),
    end: settings.scrimColor,
  ).animate(CurvedAnimation(
    parent: animation,
    curve: Interval(
      scrimAnimationStart,
      1.0,
      curve: Curves.fastOutSlowIn,
    ),
    reverseCurve: Interval(
      scrimAnimationStart,
      1.0,
      curve: Curves.fastOutSlowIn.flipped,
    ),
  ));

  if (renderBox == null) {
    return buildDefaultTransition();
  }

  final transitionColor =
      settings.transitionColor ?? Theme.of(context).colorScheme.surface;

  // Return the animated scrim with the appropriate transition as child.
  return Container(
    color: scrimAnimation.value,
    child: LayoutBuilder(
      builder: (context, constraints) => FadeTransition(
        opacity: parentToChildAnimation,
        child: Stack(
          children: <Widget>[
            // Animate the position of the child screen from the origin of
            // [renderBox] to fill the entire screen.
            PositionedTransition(
              rect:
                  positionTween(constraints).animate(positionAnimationCurve),
              child: AnimatedBuilder(
                animation: positionAnimationCurve,
                child: OverflowBox(
                  alignment: Alignment.topCenter,
                  minWidth: constraints.maxWidth,
                  maxWidth: constraints.maxWidth,
                  minHeight: constraints.maxHeight,
                  maxHeight: constraints.maxHeight,
                  child: child,
                ),
                builder: (context, child) => ClipRRect(
                  borderRadius: borderRadius.evaluate(positionAnimationCurve),
                  clipBehavior: Clip.antiAlias,
                  child: Stack(
                    children: <Widget>[
                      Container(
                        width: double.infinity,
                        height: double.infinity,
                        color: transitionColor,
                      ),
                      settings.transitionToChild
                          ? useVerticalTransition
                              ? buildVerticalTransition(child!)
                              : buildBidirectionalTransition(child!)
                          : child!,
                    ],
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    ),
  );
}