Skip to content

Commit

Permalink
Merge pull request #500 from Goddchen/fix/pop-to-named-break
Browse files Browse the repository at this point in the history
Fix: popToNamed(...), need to break from the while loop when entry found
  • Loading branch information
slovnicki committed Apr 5, 2022
2 parents 0c653f8 + 8edecbe commit cab91f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package/lib/src/beamer_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
/// `*App.router` and at least one more [Beamer] in the Widget tree.
BeamerDelegate? get parent => _parent;
set parent(BeamerDelegate? parent) {
if(parent == null && _parent != null) {
if (parent == null && _parent != null) {
_parent!.removeListener(_updateFromParent);
_parent!._children.remove(this);
_parent = null;
Expand Down Expand Up @@ -609,6 +609,7 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
} else {
beamingHistory.last.history
.removeRange(index, beamingHistory.last.history.length);
break;
}
}
beamToNamed(
Expand Down
22 changes: 22 additions & 0 deletions package/test/beamer_delegate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,26 @@ void main() {
'/t1/t2');
});
});

test('Properly preserve history part when using popToNamed(...)', () {
final delegate = BeamerDelegate(
locationBuilder: RoutesLocationBuilder(
routes: {
'/': (context, state, data) => Container(),
'/t1': (context, state, data) => Container(),
'/t2': (context, state, data) => Container(),
'/t3': (context, state, data) => Container(),
},
),
);
delegate.beamToNamed('/t1');
delegate.beamToNamed('/t2');
delegate.beamToNamed('/t3');
delegate.popToNamed('/t2');

expect(
delegate.currentBeamLocation.history
.map((HistoryElement e) => e.routeInformation.location),
orderedEquals(<String>['/t1', '/t2']));
});
}

0 comments on commit cab91f7

Please sign in to comment.