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

How to use guards with flutter_bloc states #38

Open
heshaShawky opened this issue Apr 8, 2020 · 1 comment
Open

How to use guards with flutter_bloc states #38

heshaShawky opened this issue Apr 8, 2020 · 1 comment

Comments

@heshaShawky
Copy link

I'm trying to implement the following if a user is logged in can't navigate to specific pages like login, register ...etc and if login the same can't navigate to profile ...etc

I'm using a flutter bloc Package and I have done the Authentication bloc and works great now my issue that I have ( I guess ) to access the Authentication bloc to check if the user authenticated or not and return a boolean depends on that!

So be something like that

BlocListener<AuthenticationBloc, AuthenticationState>(
  ...
);

But the problem I can't do that as far I know in SailorRouteGaurds!! or I don't know how to implement this

class Routes {
  static final Sailor sailor = Sailor();

  static void createRoutes() {
    sailor.addRoutes([
      SailorRoute(
        name: '/login', 
        builder: (context, args, params) {
          return Directionality(
            textDirection: TextDirection.rtl,
            child: LoginPage(),
          );
        },
        routeGuards: [
          SailorRouteGuard.simple(
            (context, args, params) async {
              return true;
            }
          )
        ]
      )
    ]);
  }
}
@pishguy
Copy link

pishguy commented Oct 9, 2020

@heshaShawky did you get an error?

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

2 participants