defaultOnPopPage static method
bool
defaultOnPopPage(
- BuildContext context,
- BeamerDelegate<
BeamState> delegate, - BeamPage poppedPage
The default pop behavior for BeamPage.
Implementation
static bool defaultOnPopPage(
BuildContext context,
BeamerDelegate delegate,
BeamPage poppedPage,
) {
final location = delegate.currentBeamLocation;
final previousBeamState = delegate.beamStateHistory.length > 1
? delegate.beamStateHistory[delegate.beamStateHistory.length - 2]
: null;
final pathBlueprintSegments =
List<String>.from(location.state.pathBlueprintSegments);
final pathParameters =
Map<String, String>.from(location.state.pathParameters);
final pathSegment = pathBlueprintSegments.removeLast();
if (pathSegment[0] == ':') {
pathParameters.remove(pathSegment.substring(1));
}
var beamState = BeamState(
pathBlueprintSegments: pathBlueprintSegments,
pathParameters: pathParameters,
queryParameters:
poppedPage.keepQueryOnPop ? location.state.queryParameters : {},
data: location.state.data,
);
if (beamState.uri.path == previousBeamState?.uri.path &&
!poppedPage.keepQueryOnPop) {
beamState = beamState.copyWith(
queryParameters: previousBeamState?.queryParameters,
);
}
delegate.removeLastBeamState();
location.update((state) => beamState);
return true;
}