mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
fix pushAndRemoveUntil incorrectly removes the routes below the first… (#56732)
This commit is contained in:
parent
c969b8af7b
commit
1bb9f3f718
@ -3435,9 +3435,8 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
|
||||
assert(predicate != null);
|
||||
int index = _history.length - 1;
|
||||
_history.add(_RouteEntry(newRoute, initialState: _RouteLifecycle.push));
|
||||
while (index >= 0) {
|
||||
final _RouteEntry entry = _history[index];
|
||||
if (entry.isPresent && !predicate(entry.route))
|
||||
while (index >= 0 && !predicate(_history[index].route)) {
|
||||
if (_history[index].isPresent)
|
||||
_history[index].remove();
|
||||
index -= 1;
|
||||
}
|
||||
|
@ -682,6 +682,42 @@ void main() {
|
||||
expect(find.text('B'), isOnstage);
|
||||
});
|
||||
|
||||
testWidgets('pushAndRemoveUntil does not remove routes below the first route that pass the predicate', (WidgetTester tester) async {
|
||||
// Regression https://github.com/flutter/flutter/issues/56688
|
||||
final GlobalKey<NavigatorState> navigator = GlobalKey<NavigatorState>();
|
||||
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
|
||||
'/': (BuildContext context) => const Text('home'),
|
||||
'/A': (BuildContext context) => const Text('page A'),
|
||||
'/A/B': (BuildContext context) => OnTapPage(
|
||||
id: 'B',
|
||||
onTap: () {
|
||||
Navigator.of(context).pushNamedAndRemoveUntil('/D', ModalRoute.withName('/A'));
|
||||
},
|
||||
),
|
||||
'/D': (BuildContext context) => const Text('page D'),
|
||||
};
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
navigatorKey: navigator,
|
||||
routes: routes,
|
||||
initialRoute: '/A/B',
|
||||
)
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('B'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('page D'), isOnstage);
|
||||
|
||||
navigator.currentState.pop();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('page A'), isOnstage);
|
||||
|
||||
navigator.currentState.pop();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('home'), isOnstage);
|
||||
});
|
||||
|
||||
testWidgets('replaceNamed returned value', (WidgetTester tester) async {
|
||||
Future<String> value;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user