modal_bottom_sheet icon indicating copy to clipboard operation
modal_bottom_sheet copied to clipboard

Is there an example with PageTransitionsBuilder?

Open desmeit opened this issue 3 years ago • 3 comments

The docs say that PageTransitionsBuilder works with MaterialWithModalsPageRoute. I can't find any detailed example code for it. How exactly can I change the transition with MaterialWithModalsPageRoute?

I found only this

pageRouteBuilder: <T>(RouteSettings settings, WidgetBuilder builder) => MaterialWithModalsPageRoute<T>(settings: settings, builder: builder)

But how should I implement it? What is meaning with "Using pageRouteBuilder parameter of WidgetApp"

As I understand it, within onGenerateRoute you can only take either MaterialPageRoute or PageRouteBuilder. Not both combined. This one works:

return PageRouteBuilder(
                pageBuilder: (context, animation, secondaryAnimation) => LoginPage(),
                transitionsBuilder: (context, animation, secondaryAnimation, child) {
                  return child;
                },
              );

But how can I add MaterialWithModalsPageRoute here?

desmeit avatar May 25 '21 09:05 desmeit

I solved it like this:

MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: primeColor,
          accentColor: accentColor,
          pageTransitionsTheme: PageTransitionsTheme(builders: {
            TargetPlatform.iOS: ZoomPageTransitionsBuilder(),
            TargetPlatform.android: ZoomPageTransitionsBuilder(),
          }),
        ),
        initialRoute: '/',
        onGenerateRoute: RouteGenerator.generateRoute,    
      ),

If I understand correctly that is one option and the other is to work with a WidgetsApp instead of MaterialApp. This is not possible for me because of my App Structure. Do I see that right? Then it would be great to extend the docs a bit. Thanks :-)

desmeit avatar May 25 '21 14:05 desmeit

Hello, That is perfect!

The thing is the previous route needs to be a MaterialWithModalsPageRoute. You can edit the animation on that page the same way as it is done for MaterialPageRoute, with the pageTransitionsTheme

If you use the routes param in MaterialApp, all the routes are MaterialPageRoute by default, so that should be changed. If you generate yourself the routes inside onGenerateRoute then there is nothing to worrying about

jamesblasco avatar May 25 '21 14:05 jamesblasco

Thank you very much

desmeit avatar May 25 '21 15:05 desmeit