Routing

Navigation between routes using named routes.

The router functions are defined in

class AppRouter { ... }

In the same file the style of the page transition is defined in

class CustomPageRoute1 extends MaterialPageRoute { ... }

Adding a new route

Copy one of the existing routes in the switch-case structure of the onGenerateRoute() function. Replace the route name in the casestatement and the child of the CustomPageRoute1() with the widget you want to display under the route.

Every widget that is used as route has the route name as static const route parameter to avoid misspelling of the route name in the code.

Wrapper

There are two wrapper classes

class AuthenticationWrapper extends StatefulWidget { ... }

and

class UserDataWrapper extends StatefulWidget { ... }

Wrap a route in the AuthenticationWrapperif it must be checked if the user is signed in to redirect to another page. In the template this only refers to the landing page route from which the user should be navigated to the dashboard when already signed in.

Wrap a route in the UserDataWrapper when the user data must be fetched from the database and be available for this route. In the template this refers to every route which can only be seen by logged in users.

Last updated