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,
) {
  var size=MediaQuery.of(context).size;
  if(height!=null){
    if(top==null){
      if(bottom==null){
        this.top=(size.height-height!)/2;
        bottom=top;
      }else{
        top=size.height-height!-bottom!;
      }
    }else if(bottom==null)bottom=size.height-height!-top!;
  }else{
    top=(top??10);bottom=(bottom??20);
  }
  if(width!=null){
    if(left==null){
      if(right==null){
        this.left=(size.width-width!)/2;
        right=left;
      }else{
        left=size.width-width!-right!;
      }
    }else if(right==null)right=size.width-width!-left!;
  }else{
    left=(left??20);right=(right??20);
  }

  return GestureDetector(
    onTap: () {
      // call this method here to hide soft keyboard
      SystemChannels.textInput.invokeMethod('TextInput.hide');
    },
    child: Material(
      // This makes sure that text and other content follows the material style
      type: MaterialType.transparency,
      //type: MaterialType.canvas,
      // make sure that the overlay content is not cut off
      child: SafeArea(
        bottom: true,
        child: _buildOverlayContent(context),
      ),
    ),
  );
}