Flutter: Fade widgets in after navigation

Viewed 275

Consider two routes, A and B. After navigating from A to B, how can I get the widgets in B to fade in (go from opacity 0 to 1) gradually?

1 Answers

It seems like you what you are looking for is a PageRouteBuilder with a custom transition, like so:

return Navigator.of(context).push(PageRouteBuilder(
  pageBuilder: (context, animation, secondaryAnimation) {
    return HomePage();
  },
  transitionDuration: Duration(milliseconds: 500),
  transitionsBuilder: (context, animation, secondaryAnimation, child) {
    return FadeTransition(
      opacity: animation,
      child: child,
    );
  }
));
Related