WayFar
Search…
⌃K

Navigation and routes

Routing

When you add a new screen, you have to register it in ROUTES static class, in the file lib/core/navigation/routes.dart :
routes.dart
class ROUTES {
static final String Home = "/";
static final String Example = "/example";
...
}
Now map it to the corresponding widget (screen) using the registerRoutes function :
routes.dart
Map<String, WidgetBuilder> registerRoutes() {
return <String, WidgetBuilder>{
ROUTES.Home: (context) => AuthGuard(context, Home()),
ROUTES.Examle: (context) => ExampleScreen(),
...
};
}
If the screen needs arguments, use the function onGenerateAppRoute to pass parameters to the screen :
routes.dart
Route onGenerateAppRoute(RouteSettings settings) {
var route = settings.name;
if (route==ROUTES.ParkingDetails) {
// Read arguments from RouteSettings
RouteArgs<String> args = settings.arguments as RouteArgs<String>;
return MaterialPageRoute(
builder: (context) {
return AuthGuard(context, ParkingDetailScreen(
parkingId: args.value,
));
},
);
}

Protecting routes

To protect routes from unauthorized access, an authentication guard has been implemented (AuthGuard).
If the user is not authenticated, the guard redirect it to the sign in screen, otherwise the access is granted :
auth_guard.dart
Widget AuthGuard(BuildContext context, Widget widget) {
return BlocBuilder<AuthenticationBloc, AuthenticationState>(
bloc: resolve<AuthenticationBloc>(),
builder: (BuildContext context, state) {
if (state is Uninitialized) return Scaffold(body: Container());
return (state is Authenticated) ? widget : SignInScreen();
},
);
}

Drawer menu

To be able to add or edit items form the application drawer menu, head over to the file menu.dart under lib/core/navigation.
You can add a record by giving it a key, an icon and the corresponding route :
menu.dart
final menu = [
{
"key": "home",
"icon": FontAwesomeIcons.home,
"route": ROUTES.Home,
},
...
]