Update PopupRoute docs and add an example (#106948)

This commit is contained in:
Taha Tesser
2022-07-12 11:59:05 +03:00
committed by GitHub
parent a8d047923b
commit 66cd09dd82
5 changed files with 178 additions and 11 deletions

View File

@@ -0,0 +1,40 @@
// 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/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/widgets/routes/popup_route.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Dismiss dialog with tap on the scrim and escape key', (WidgetTester tester) async {
const String dialogText = 'Tap in the scrim or press escape key to dismiss.';
await tester.pumpWidget(
const example.PopupRouteApp(),
);
expect(find.text(dialogText), findsNothing);
// Tap on the button to show the dialog.
await tester.tap(find.byType(OutlinedButton));
await tester.pumpAndSettle();
expect(find.text(dialogText), findsOneWidget);
// Try to dismiss the dialog with a tap on the scrim.
await tester.tapAt(const Offset(10.0, 10.0));
await tester.pumpAndSettle();
expect(find.text(dialogText), findsNothing);
// Open the dialog again.
await tester.tap(find.byType(OutlinedButton));
await tester.pumpAndSettle();
expect(find.text(dialogText), findsOneWidget);
// Try to dismiss the dialog with the escape key.
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(find.text(dialogText), findsNothing);
});
}

View File

@@ -0,0 +1,29 @@
// 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/material.dart';
import 'package:flutter_api_samples/widgets/routes/show_general_dialog.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Open and dismiss general dialog', (WidgetTester tester) async {
const String dialogText = 'Alert!';
await tester.pumpWidget(
const example.GeneralDialogApp(),
);
expect(find.text(dialogText), findsNothing);
// Tap on the button to show the dialog.
await tester.tap(find.byType(OutlinedButton));
await tester.pumpAndSettle();
expect(find.text(dialogText), findsOneWidget);
// Try to dismiss the dialog with a tap on the scrim.
await tester.tapAt(const Offset(10.0, 10.0));
await tester.pumpAndSettle();
expect(find.text(dialogText), findsNothing);
});
}