buildPage method

  1. @override
Widget buildPage(
  1. BuildContext context,
  2. Animation<double> animation,
  3. Animation<double> secondaryAnimation
)
override

Override this method to build the primary content of this route.

The arguments have the following meanings:

  • context: The context in which the route is being built.
  • animation: The animation for this route's transition. When entering, the animation runs forward from 0.0 to 1.0. When exiting, this animation runs backwards from 1.0 to 0.0.
  • secondaryAnimation: The animation for the route being pushed on top of this route. This animation lets this route coordinate with the entrance and exit transition of routes pushed on top of this route.

This method is only called when the route is first built, and rarely thereafter. In particular, it is not automatically called again when the route's state changes unless it uses ModalRoute.of. For a builder that is called every time the route's state changes, consider buildTransitions. For widgets that change their behavior when the route's state changes, consider ModalRoute.of to obtain a reference to the route; this will cause the widget to be rebuilt each time the route changes state.

In general, buildPage should be used to build the page contents, and buildTransitions for the widgets that change as the page is brought in and out of view. Avoid using buildTransitions for content that never changes; building such content once from buildPage is more efficient.

Implementation

@override
Widget buildPage(BuildContext context, Animation<double> animation,
    Animation<double> secondaryAnimation) {
  // By definition, the bottom sheet is aligned to the bottom of the page
  // and isn't exposed to the top padding of the MediaQuery.
  Widget bottomSheet = MediaQuery.removePadding(
    context: context,
    // removeTop: true,
    child: _ModalBottomSheet<T>(
      closeProgressThreshold: closeProgressThreshold,
      route: this,
      secondAnimationController: secondAnimationController,
      expanded: expanded,
      bounce: bounce,
      enableDrag: enableDrag,
      animationCurve: animationCurve,
    ),
  );
  return bottomSheet;
}