Skip to content

Commit d7fac5d

Browse files
sm-sayedignprice
authored andcommitted
nav test: Make TestNavigatorObserver extend TransitionDurationObserver
This way, we can use the instance of TestNavigatorObserver to wait for the route transition to complete, instead of creating a different object of TransitionDurationObserver for the same purpose.
1 parent 1670a8c commit d7fac5d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

test/test_navigation.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import 'package:flutter/widgets.dart';
2+
import 'package:flutter_test/flutter_test.dart';
23

34
// Inspired by test code in the Flutter tree:
45
// https://github.com/flutter/flutter/blob/53082f65b/packages/flutter/test/widgets/observer_tester.dart
56
// https://github.com/flutter/flutter/blob/53082f65b/packages/flutter/test/widgets/navigator_test.dart
67

78
/// A trivial observer for testing the navigator.
8-
class TestNavigatorObserver extends NavigatorObserver {
9+
class TestNavigatorObserver extends TransitionDurationObserver{
910
void Function(Route<dynamic> topRoute, Route<dynamic>? previousTopRoute)? onChangedTop;
1011
void Function(Route<dynamic> route, Route<dynamic>? previousRoute)? onPushed;
1112
void Function(Route<dynamic> route, Route<dynamic>? previousRoute)? onPopped;
@@ -16,36 +17,43 @@ class TestNavigatorObserver extends NavigatorObserver {
1617

1718
@override
1819
void didChangeTop(Route<dynamic> topRoute, Route<dynamic>? previousTopRoute) {
20+
super.didChangeTop(topRoute, previousTopRoute);
1921
onChangedTop?.call(topRoute, previousTopRoute);
2022
}
2123

2224
@override
2325
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
26+
super.didPush(route, previousRoute);
2427
onPushed?.call(route, previousRoute);
2528
}
2629

2730
@override
2831
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
32+
super.didPop(route, previousRoute);
2933
onPopped?.call(route, previousRoute);
3034
}
3135

3236
@override
3337
void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) {
38+
super.didRemove(route, previousRoute);
3439
onRemoved?.call(route, previousRoute);
3540
}
3641

3742
@override
3843
void didReplace({ Route<dynamic>? oldRoute, Route<dynamic>? newRoute }) {
44+
super.didReplace(oldRoute: oldRoute, newRoute: newRoute);
3945
onReplaced?.call(newRoute, oldRoute);
4046
}
4147

4248
@override
4349
void didStartUserGesture(Route<dynamic> route, Route<dynamic>? previousRoute) {
50+
super.didStartUserGesture(route, previousRoute);
4451
onStartUserGesture?.call(route, previousRoute);
4552
}
4653

4754
@override
4855
void didStopUserGesture() {
56+
super.didStopUserGesture();
4957
onStopUserGesture?.call();
5058
}
5159
}

0 commit comments

Comments
 (0)