sailor
sailor copied to clipboard
How to use guards with flutter_bloc states
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;
}
)
]
)
]);
}
}
@heshaShawky did you get an error?