|
5 | 5 | import 'dart:ui';
|
6 | 6 |
|
7 | 7 | import 'package:flutter/cupertino.dart';
|
| 8 | +import 'package:flutter/foundation.dart'; |
8 | 9 | import 'package:flutter/material.dart';
|
9 | 10 | import 'package:flutter/rendering.dart';
|
10 | 11 | import 'package:flutter/services.dart';
|
@@ -61,6 +62,16 @@ Finder _findButtonBar() {
|
61 | 62 | return find.ancestor(of: find.byType(OverflowBar), matching: find.byType(Padding)).first;
|
62 | 63 | }
|
63 | 64 |
|
| 65 | +// In the case of [AlertDialog], it takes up the entire screen, since it also |
| 66 | +// contains the scrim. The first [Material] child of [AlertDialog] is the actual |
| 67 | +// dialog itself. |
| 68 | +Size _getDialogSize(WidgetTester tester) => tester.getSize( |
| 69 | + find.descendant( |
| 70 | + of: find.byType(AlertDialog), |
| 71 | + matching: find.byType(Material), |
| 72 | + ).first, |
| 73 | +); |
| 74 | + |
64 | 75 | const ShapeBorder _defaultM2DialogShape = RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0)));
|
65 | 76 | final ShapeBorder _defaultM3DialogShape = RoundedRectangleBorder(borderRadius: BorderRadius.circular(28.0));
|
66 | 77 |
|
@@ -144,6 +155,8 @@ void main() {
|
144 | 155 | expect(material3Widget.color, material3Theme.colorScheme.surface);
|
145 | 156 | expect(material3Widget.shape, _defaultM3DialogShape);
|
146 | 157 | expect(material3Widget.elevation, 6.0);
|
| 158 | + // For some unknown reason, one pixel wider on web (HTML). |
| 159 | + expect(_getDialogSize(tester), Size(280.0, isBrowser && !isCanvasKit ? 141.0 : 140.0)); |
147 | 160 | });
|
148 | 161 |
|
149 | 162 | testWidgets('Dialog.fullscreen Defaults', (WidgetTester tester) async {
|
@@ -337,6 +350,26 @@ void main() {
|
337 | 350 | expect(bottomLeft.dy, 576.0);
|
338 | 351 | });
|
339 | 352 |
|
| 353 | + testWidgets('Dialog respects constraints with large content on large screens', (WidgetTester tester) async { |
| 354 | + const AlertDialog dialog = AlertDialog( |
| 355 | + actions: <Widget>[ ], |
| 356 | + content: SizedBox( |
| 357 | + width: 1000.0, |
| 358 | + height: 1000.0, |
| 359 | + ), |
| 360 | + ); |
| 361 | + |
| 362 | + tester.view.physicalSize = const Size(2000, 2000); |
| 363 | + addTearDown(tester.view.resetPhysicalSize); |
| 364 | + |
| 365 | + await tester.pumpWidget(_buildAppWithDialog(dialog, theme: material3Theme)); |
| 366 | + |
| 367 | + await tester.tap(find.text('X')); |
| 368 | + await tester.pumpAndSettle(); |
| 369 | + |
| 370 | + expect(_getDialogSize(tester), const Size(560.0, 560.0)); |
| 371 | + }); |
| 372 | + |
340 | 373 | testWidgets('Simple dialog control test', (WidgetTester tester) async {
|
341 | 374 | await tester.pumpWidget(
|
342 | 375 | const MaterialApp(
|
@@ -593,15 +626,8 @@ void main() {
|
593 | 626 | await tester.tap(find.text('X'));
|
594 | 627 | await tester.pumpAndSettle();
|
595 | 628 |
|
596 |
| - // The [AlertDialog] is the entire screen, since it also contains the scrim. |
597 |
| - // The first [Material] child of [AlertDialog] is the actual dialog |
598 |
| - // itself. |
599 |
| - final Size dialogSize = tester.getSize( |
600 |
| - find.descendant( |
601 |
| - of: find.byType(AlertDialog), |
602 |
| - matching: find.byType(Material), |
603 |
| - ).first, |
604 |
| - ); |
| 629 | + |
| 630 | + final Size dialogSize = _getDialogSize(tester); |
605 | 631 | final Size actionsSize = tester.getSize(_findButtonBar());
|
606 | 632 |
|
607 | 633 | expect(actionsSize.width, dialogSize.width);
|
@@ -629,15 +655,7 @@ void main() {
|
629 | 655 | await tester.tap(find.text('X'));
|
630 | 656 | await tester.pumpAndSettle();
|
631 | 657 |
|
632 |
| - // The [AlertDialog] is the entire screen, since it also contains the scrim. |
633 |
| - // The first [Material] child of [AlertDialog] is the actual dialog |
634 |
| - // itself. |
635 |
| - final Size dialogSize = tester.getSize( |
636 |
| - find.descendant( |
637 |
| - of: find.byType(AlertDialog), |
638 |
| - matching: find.byType(Material), |
639 |
| - ).first, |
640 |
| - ); |
| 658 | + final Size dialogSize = _getDialogSize(tester); |
641 | 659 | final Size actionsSize = tester.getSize(find.byType(OverflowBar));
|
642 | 660 |
|
643 | 661 | expect(actionsSize.width, dialogSize.width - (30.0 * 2));
|
|
0 commit comments