Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated Route Access With Flow Builder #101

Open
mstfkhazaal opened this issue Aug 3, 2022 · 0 comments
Open

Generated Route Access With Flow Builder #101

mstfkhazaal opened this issue Aug 3, 2022 · 0 comments

Comments

@mstfkhazaal
Copy link

I'm new to this package, I have nested routes with Authentication and many many blocs and i use Generated Route Access

Generated Route

class AppRouter {
  AppRouter();
  static final loginBloc = LoginCubit(
    authBloc: authBloc,
  );
 static final authBloc = AuthBloc();
  static const String home = '/';
  static const String login = 'login';
  static const String profile = '/profile';
Route<dynamic> onGenerateRoute(RouteSettings settings) {
    switch (settings.name) {
      /// Auth
      case home:
      case login:
        return MaterialPageRoute<dynamic>(
          builder: (_) => MultiBlocProvider(
            providers: [
              BlocProvider<AuthBloc>.value(
                value: authBloc,
              ),
              BlocProvider<LoginCubit>.value(
                value: loginBloc,
              ),
            ],
            child: const AuthFlow(),
          ),
        );

      /// Profile
      case profile:
        return MaterialPageRoute<dynamic>(
          builder: (_) => MultiBlocProvider(
            providers: [
              BlocProvider<AuthBloc>.value(
                value: authBloc,
              ),
            ],
            child: const ProfilePage(),
          ),
        );
}

i use Flow Builder in Authentication

class AuthFlow extends StatelessWidget {
  const AuthFlow({super.key});
  @override
  Widget build(BuildContext context) {
    return FlowBuilder<AuthState>(
      state: context.select((AuthBloc state) => state.state),
      onGeneratePages: (projectState, pages) {
        if (projectState.status == AuthenticationStatus.authenticated) {
          context.read<ProjectBloc>().add(const GetListProject());
          context.read<NewsBloc>().add(const GetList());
        }
        return [
          if (projectState.status == AuthenticationStatus.authenticated)
            const MaterialPage<dynamic>(child: HomePage())
          else
            const MaterialPage<dynamic>(child: LoginPage()),
        ];
      },
    );
  }
}

But inside the HomePage when i go to the profile this error appears

Navigation Code
Navigator.of(context).pushNamed(AppRouter.profile);

Error Code
Navigator.onGenerateRoute was null, but the route named "/profile" was referenced. To use the Navigator API with named routes (pushNamed, pushReplacementNamed, or pushNamedAndRemoveUntil), the Navigator must be provided with an onGenerateRoute handler.

Is there another way to use the library with Generated Route?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant