mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

fixes https://github.com/flutter/flutter/issues/137458 Chagnes: 1. Navigator.pop will always pop page based route 2. add a onDidRemovePage callback to replace onPopPage 3. Page.canPop and Page.onPopInvoked mirrors the PopScope, but in Page class. migration guide https://github.com/flutter/website/pull/10523
55 lines
1.7 KiB
Dart
55 lines
1.7 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/page/page_can_pop.0.dart' as example;
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import '../navigator_utils.dart';
|
|
|
|
void main() {
|
|
testWidgets('Can choose to stay on page', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
const example.PageApiExampleApp(),
|
|
);
|
|
|
|
expect(find.text('Home'), findsOneWidget);
|
|
|
|
await tester.tap(find.text('Go to details'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Home'), findsNothing);
|
|
expect(find.text('Details'), findsOneWidget);
|
|
|
|
await simulateSystemBack();
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Are you sure?'), findsOneWidget);
|
|
|
|
await tester.tap(find.text('Cancel'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Home'), findsNothing);
|
|
expect(find.text('Details'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('Can choose to go back', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
const example.PageApiExampleApp(),
|
|
);
|
|
|
|
expect(find.text('Home'), findsOneWidget);
|
|
|
|
await tester.tap(find.text('Go to details'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Home'), findsNothing);
|
|
expect(find.text('Details'), findsOneWidget);
|
|
|
|
await simulateSystemBack();
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Are you sure?'), findsOneWidget);
|
|
|
|
await tester.tap(find.text('Confirm'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Details'), findsNothing);
|
|
expect(find.text('Home'), findsOneWidget);
|
|
});
|
|
}
|