简体   繁体   中英

flutter Custom PageRouteBuilder

Custom Route like this:

class FadeRouteBuilder extends PageRouteBuilder {
  final Widget page;
  final int duration;


  FadeRouteBuilder({this.page, this.duration = 1000})
      : super(
          transitionDuration: Duration(milliseconds: duration),
          //Page builder doesn't do anything special, just return the ui.page we were passed in.
          pageBuilder: (context, animation, secondaryAnimation) => page,
          //transitionsBuilder builds 2 nested transitions, one for transitionIn (animation), and one for transitionOut (secondaryAnimation)
          transitionsBuilder: (context, animation, secondaryAnimation, child) {
            return FadeTransition(
                //Transition from 0 - 1 when coming on the screen
                opacity: Tween<double>(begin: 0, end: 1).animate(animation),
                child: FadeTransition(
                  //Transition from 1 to 0 when leaving the screen
                  opacity: Tween<double>(begin: 1, end: 0)
                      .animate(secondaryAnimation),
                  child: child,
                ));
          },
        );
}

A page containing CustomScrollView is PageA,to navgitor PageB by FadeRouteBuilder,

when I pop pageB,I drag PageA list and hold,when PageB closed,CustomScrollView can't tap,is invalid.

I use a variable to determine if Page B is closed。 在此处输入图像描述

Although it solves the problem, it is not elegant enough, If there is a better solution, please answer me. thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM