apply method
bool
apply(
- BuildContext context,
- BeamerDelegate delegate,
- BeamLocation<
RouteInformationSerializable> origin, - List<
BeamPage> currentPages, - BeamLocation<
RouteInformationSerializable> target, - String? deepLink,
Applies the guard. TODO add detailed comments
Implementation
bool apply(
BuildContext context,
BeamerDelegate delegate,
BeamLocation origin,
List<BeamPage> currentPages,
BeamLocation target,
String? deepLink,
) {
final checkPassed = check(context, target);
if (checkPassed) {
return false;
}
onCheckFailed?.call(context, target);
if (showPage != null) {
final redirectBeamLocation =
GuardShowPage(target.state.routeInformation, showPage!);
if (replaceCurrentStack) {
delegate.beamToReplacement(redirectBeamLocation);
} else {
delegate.beamTo(redirectBeamLocation);
}
return true;
}
// just block navigation
// revert the configuration of delegate
if (beamTo == null && beamToNamed == null) {
delegate.configuration = origin.state.routeInformation;
return true;
}
if (beamTo != null) {
final redirectBeamLocation = beamTo!(context, origin, target, deepLink);
if (redirectBeamLocation.state.routeInformation.uri ==
target.state.routeInformation.uri) {
// just block if this will produce an immediate infinite loop
return true;
}
if (redirectBeamLocation.state.routeInformation.uri ==
origin.state.routeInformation.uri) {
// just block if redirect is the current route
return true;
}
if (replaceCurrentStack) {
delegate.beamToReplacement(redirectBeamLocation);
} else {
delegate.beamTo(redirectBeamLocation);
}
if (redirectBeamLocation.state.routeInformation.uri.toString() ==
deepLink) {
delegate.setDeepLink(null);
}
return true;
}
if (beamToNamed != null) {
final redirectNamed = beamToNamed!(origin, target, deepLink);
if (redirectNamed == target.state.routeInformation.uri.toString()) {
// just block if this will produce an immediate infinite loop
return true;
}
if (redirectNamed == origin.state.routeInformation.uri.toString()) {
// just block if redirect is the current route
return true;
}
if (replaceCurrentStack) {
delegate.beamToReplacementNamed(redirectNamed);
} else {
delegate.beamToNamed(redirectNamed);
}
if (redirectNamed == deepLink) {
delegate.setDeepLink(null);
}
return true;
}
return false;
}