setInitialRoutePath method
Called by the Router at startup with the structure that the RouteInformationParser obtained from parsing the initial route.
This should configure the RouterDelegate so that when build is invoked, it will create a widget tree that matches the initial route.
By default, this method forwards the configuration
to setNewRoutePath.
Consider using a SynchronousFuture if the result can be computed synchronously, so that the Router does not need to wait for the next microtask to schedule a build.
See also:
- setRestoredRoutePath, which is called instead of this method during state restoration.
Implementation
@override
Future<void> setInitialRoutePath(UrlState configuration) {
// setInitialRoutePath is re-fired on enabling
// select widget mode from flutter inspector,
// this check is preventing it from rebuilding the app
if (controller.hasEntries) {
return SynchronousFuture(null);
}
if (initialRoutes?.isNotEmpty == true) {
return controller.pushAll(initialRoutes!);
} else if (initialDeepLink != null) {
return controller.pushNamed(initialDeepLink!, includePrefixMatches: true);
} else if (configuration.hasSegments) {
_onNewUrlState(configuration);
return controller.navigateAll(configuration.segments);
} else {
throw FlutterError("Can not resolve initial route");
}
}