gurleensethi / sailor

Easy page navigation and management in Flutter apps.
https://pub.dev/packages/sailor
MIT License
145 stars 24 forks source link

How to use guards with flutter_bloc states #38

Open heshaShawky opened 4 years ago

heshaShawky commented 4 years ago

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 commented 3 years ago

@heshaShawky did you get an error?