flutter/examples/api/test/widgets/routes/route_observer.0_test.dart
Taha Tesser 536de5ed91
Update RouteObserver example and fix an error thrown (#141166)
fixes [`RouteObserver` example throws an error](https://github.com/flutter/flutter/issues/141078)

### Description
This updates the `RouteObserver` example from snippet to Dartpad example and fixes the error when running the code snippet
2024-01-09 20:48:56 +00:00

42 lines
1.5 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_api_samples/widgets/routes/route_observer.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('RouteObserver notifies RouteAware widget', (WidgetTester tester) async {
await tester.pumpWidget(
const example.RouteObserverApp(),
);
// Check the initial RouteObserver logs.
expect(find.text('didPush'), findsOneWidget);
// Tap on the button to push a new route.
await tester.tap(find.text('Go to next page'));
await tester.pumpAndSettle();
// Tap on the button to go back to the previous route.
await tester.tap(find.text('Go back to RouteAware page'));
await tester.pumpAndSettle();
// Check the RouteObserver logs after the route is popped.
expect(find.text('didPush'), findsOneWidget);
expect(find.text('didPopNext'), findsOneWidget);
// Tap on the button to push a new route again.
await tester.tap(find.text('Go to next page'));
await tester.pumpAndSettle();
// Tap on the button to go back to the previous route again.
await tester.tap(find.text('Go back to RouteAware page'));
await tester.pumpAndSettle();
// Check the RouteObserver logs after the route is popped again.
expect(find.text('didPush'), findsOneWidget);
expect(find.text('didPopNext'), findsNWidgets(2));
});
}