mirror of
https://github.com/flutter/flutter.git
synced 2026-02-04 19:00:09 +08:00
Improve error message when using popuntil with bad predicate (#57247)
This commit is contained in:
parent
af9b6a6efa
commit
68037a23af
@ -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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user