vaishnav
vaishnav

Reputation: 67

Flutter: Fade widgets in after navigation

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?

Upvotes: 2

Views: 610

Answers (1)

J. S.
J. S.

Reputation: 9625

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,
    );
  }
));

Upvotes: 4

Related Questions