kalismeras61 / flutter_page_transition

This is Flutter Page Transition Package
BSD 2-Clause "Simplified" License
471 stars 56 forks source link

Is it possible to use PageTransition with the Navigator 2.0 List of Pages? #47

Closed JonasHiltl closed 2 years ago

JonasHiltl commented 3 years ago

I'm defining an App Navigator that shows screens based on the state of my app. The screens are wrapped with a MaterialPage but I would like to implement pageTransitions with this logic. Is it possible to implement page transitions with this kind of logic or would I have to define the routes through onGenerateRoute?

class AppNavigator extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return BlocBuilder<SessionCubit, SessionState>(
      builder: (context, state) {
        return Navigator(
          pages: [
            if (state is UnkownSessionState)
              MaterialPage(child: StartupScreen()),
            //show auth flow
            if (state is Unverified)
              MaterialPage(
                  child: BlocProvider(
                create: (context) => AuthCubit(context.read<SessionCubit>()),
                child: AuthNavigator(),
              )),
            //show session flow
            if (state is Verified) MaterialPage(child: Home())
          ],
          onPopPage: (route, result) => route.didPop(result),
        );
      },
    );
  }
}

I would for example like the Home screen to always fade in with the transition PageTransitionType.fade

marcov-dart commented 2 years ago

I use this package with navigator 2.0. Instead of MaterialPage I use TransitionPage defined like below:

class TransitionPage extends Page { final Widget child; final PageTransitionType transition;

const TransitionPage({ LocalKey? key, String? name, Object? arguments, required this.transition, required this.child, }) : super(key: key, name: name, arguments: arguments);

@override Route createRoute(BuildContext context) { return PageTransition( settings: this, type: transition, child: child, ); } }