buildRoute method
Builds a Widget for the given route url or id. This is used for top-level documents called routes. These could represent a page, dialog or a conditional-route.
Implementation
@override
Widget buildRoute(BuildContext context, {Uri? url, String? routeId}) {
final label = [
url == null ? null : 'Url: $url',
routeId == null ? null : 'RouteId: $routeId',
'Route',
].firstWhere((x) => x != null);
return ScopedDIWidget(
debugLabel: 'Scoped DI for $label',
child: RouteFutureBuilder(
url: url,
routeId: routeId,
fetchRoute: (context, {path, routeId}) => provider
.fetchRoute(path: path, routeId: routeId)
.then((value) async {
if (!context.mounted) {
return null;
}
// Reset DI scope when a new route is fetched
await context.di.reset();
if (!context.mounted) {
return null;
}
// Now initialize the new route, since the DI scope has been reset
// and we have a clean slate for new registrations
final finalRoute = await value?.init(context);
return finalRoute;
}),
buildContent: buildContent,
),
);
}