route static method
GoRoute
route({
- required String path,
- required Widget builder(
- BuildContext context,
- BloomRouteMatch match
- String? name,
- List<
BloomGuard> guards = const [], - List<
RouteBase> routes = const [],
Helper to create a GoRoute with Bloom route match and guard resolution.
Parameters:
path: Route path pattern (e.g.'/users/:id').builder: Widget builder receiving the current context and BloomRouteMatch.name: Optional route name.guards: Route-specific guards.routes: Sub-routes nested under this route.
Implementation
static GoRoute route({
required String path,
required Widget Function(BuildContext context, BloomRouteMatch match) builder,
String? name,
List<BloomGuard> guards = const [],
List<RouteBase> routes = const [],
}) {
return GoRoute(
path: path,
name: name,
routes: routes,
redirect: (context, state) async {
if (guards.isEmpty) return null;
final match = BloomRouteMatch(
location: state.uri.toString(),
path: state.matchedLocation,
pathParameters: state.pathParameters,
queryParameters: state.uri.queryParameters,
extra: state.extra,
);
for (final guard in guards) {
final result = await guard.canActivate(context, match);
if (!result.isAllowed) {
return result.redirectPath ?? '/';
}
}
return null;
},
builder: (context, state) {
final match = BloomRouteMatch(
location: state.uri.toString(),
path: state.matchedLocation,
pathParameters: state.pathParameters,
queryParameters: state.uri.queryParameters,
extra: state.extra,
);
return builder(context, match);
},
);
}