Unverified Commit 68037a23 authored by chunhtai's avatar chunhtai Committed by GitHub

Improve error message when using popuntil with bad predicate (#57247)

parent af9b6a6e
......@@ -3642,8 +3642,12 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
/// ```
/// {@end-tool}
void popUntil(RoutePredicate predicate) {
while (!predicate(_history.lastWhere(_RouteEntry.isPresentPredicate).route)) {
_RouteEntry candidate = _history.lastWhere(_RouteEntry.isPresentPredicate, orElse: () => null);
while(candidate != null) {
if (predicate(candidate.route))
return;
pop();
candidate = _history.lastWhere(_RouteEntry.isPresentPredicate, orElse: () => null);
}
}
......
......@@ -696,6 +696,33 @@ void main() {
expect(find.text('C'), isOnstage);
});
testWidgets('Able to pop all routes', (WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/' : (BuildContext context) => const OnTapPage(
id: '/',
),
'/A': (BuildContext context) => const OnTapPage(
id: 'A',
),
'/A/B': (BuildContext context) => OnTapPage(
id: 'B',
onTap: (){
// Pops all routes with bad predicate.
Navigator.of(context).popUntil((Route<dynamic> route) => false);
},
),
};
await tester.pumpWidget(
MaterialApp(
routes: routes,
initialRoute: '/A/B',
)
);
await tester.tap(find.text('B'));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
});
testWidgets('pushAndRemoveUntil triggers secondaryAnimation', (WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/' : (BuildContext context) => OnTapPage(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment