Skip to content

Commit

Permalink
{beamer_delegate}: [add] initializeFromParent option
Browse files Browse the repository at this point in the history
	- closes #447
  • Loading branch information
slovnicki committed Jan 20, 2022
1 parent 3325982 commit 340b474
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions package/lib/src/beamer_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
this.beamBackTransitionDelegate = const ReverseTransitionDelegate(),
this.onPopPage,
this.setBrowserTabTitle = true,
this.initializeFromParent = true,
this.updateFromParent = true,
this.updateParent = true,
this.clearBeamingHistoryOn = const <String>{},
Expand All @@ -58,7 +59,7 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
BeamerDelegate? get parent => _parent;
set parent(BeamerDelegate? parent) {
_parent = parent!;
_initializeFromParent();
_initialize();
if (updateFromParent) {
_parent!.addListener(_updateFromParent);
}
Expand Down Expand Up @@ -196,6 +197,11 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
/// be used to set and update the browser tab title.
final bool setBrowserTabTitle;

/// Whether to take [configuration] from parent when this is created.
///
/// If false, the [initialPath] will be used.
final bool initializeFromParent;

/// Whether to call [update] when parent notifies listeners.
///
/// This means that navigation can be done either on parent or on this
Expand Down Expand Up @@ -900,12 +906,12 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
return route.didPop(result);
}

void _initializeFromParent() {
void _initialize() {
final parent = _parent;
if (parent == null) {
return;
}
configuration = updateFromParent
configuration = initializeFromParent
? parent.configuration.copyWith()
: parent.configuration.copyWith(location: initialPath);
var location = locationBuilder(
Expand Down
1 change: 1 addition & 0 deletions package/test/beamer_delegate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ void main() {
testWidgets("navigation on parent doesn't update nested Beamer",
(tester) async {
final childDelegate = BeamerDelegate(
initializeFromParent: false,
updateFromParent: false,
locationBuilder: RoutesLocationBuilder(
routes: {
Expand Down

0 comments on commit 340b474

Please sign in to comment.