diff --git a/packages/flutter/lib/src/material/dialog.dart b/packages/flutter/lib/src/material/dialog.dart index 63d2b42740d..9f3a967bfcc 100644 --- a/packages/flutter/lib/src/material/dialog.dart +++ b/packages/flutter/lib/src/material/dialog.dart @@ -24,8 +24,6 @@ import 'theme_data.dart'; const EdgeInsets _defaultInsetPadding = EdgeInsets.symmetric(horizontal: 40.0, vertical: 24.0); -const BoxConstraints _dialogConstraints = BoxConstraints(minWidth: 280.0, maxWidth: 560.0, maxHeight: 560.0); - /// A Material Design dialog. /// /// This dialog widget does not have any opinion about the contents of the @@ -234,7 +232,7 @@ class Dialog extends StatelessWidget { dialogChild = Align( alignment: alignment ?? dialogTheme.alignment ?? defaults.alignment!, child: ConstrainedBox( - constraints: _constraintsScaleFactor(MediaQuery.of(context).textScaleFactor, theme.useMaterial3), + constraints: const BoxConstraints(minWidth: 280.0), child: Material( color: backgroundColor ?? dialogTheme.backgroundColor ?? Theme.of(context).dialogBackgroundColor, elevation: elevation ?? dialogTheme.elevation ?? defaults.elevation!, @@ -1263,7 +1261,7 @@ class SimpleDialog extends StatelessWidget { Widget dialogChild = IntrinsicWidth( stepWidth: 56.0, child: ConstrainedBox( - constraints: _constraintsScaleFactor(MediaQuery.of(context).textScaleFactor, theme.useMaterial3), + constraints: const BoxConstraints(minWidth: 280.0), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, @@ -1589,17 +1587,6 @@ double _paddingScaleFactor(double textScaleFactor) { return lerpDouble(1.0, 1.0 / 3.0, clampedTextScaleFactor - 1.0)!; } -BoxConstraints _constraintsScaleFactor(double textScaleFactor, bool useMaterial3) { - if (!useMaterial3) { - return const BoxConstraints(minWidth: 280.0); - } else { - return textScaleFactor == 1.0 - ? _dialogConstraints - // Scale the max height of the dialog by the text scale factor to aid in readability. - : _dialogConstraints.copyWith(maxHeight: _dialogConstraints.maxHeight * textScaleFactor); - } -} - // Hand coded defaults based on Material Design 2. class _DialogDefaultsM2 extends DialogTheme { _DialogDefaultsM2(this.context) diff --git a/packages/flutter/test/material/dialog_test.dart b/packages/flutter/test/material/dialog_test.dart index f010e514105..df5c649323c 100644 --- a/packages/flutter/test/material/dialog_test.dart +++ b/packages/flutter/test/material/dialog_test.dart @@ -5,7 +5,6 @@ import 'dart:ui'; import 'package:flutter/cupertino.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; @@ -62,16 +61,6 @@ Finder _findButtonBar() { return find.ancestor(of: find.byType(OverflowBar), matching: find.byType(Padding)).first; } -// In the case of [AlertDialog], it takes up the entire screen, since it also -// contains the scrim. The first [Material] child of [AlertDialog] is the actual -// dialog itself. -Size _getDialogSize(WidgetTester tester) => tester.getSize( - find.descendant( - of: find.byType(AlertDialog), - matching: find.byType(Material), - ).first, -); - const ShapeBorder _defaultM2DialogShape = RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))); final ShapeBorder _defaultM3DialogShape = RoundedRectangleBorder(borderRadius: BorderRadius.circular(28.0)); @@ -155,8 +144,6 @@ void main() { expect(material3Widget.color, material3Theme.colorScheme.surface); expect(material3Widget.shape, _defaultM3DialogShape); expect(material3Widget.elevation, 6.0); - // For some unknown reason, one pixel wider on web (HTML). - expect(_getDialogSize(tester), Size(280.0, isBrowser && !isCanvasKit ? 141.0 : 140.0)); }); testWidgets('Dialog.fullscreen Defaults', (WidgetTester tester) async { @@ -350,26 +337,6 @@ void main() { expect(bottomLeft.dy, 576.0); }); - testWidgets('Dialog respects constraints with large content on large screens', (WidgetTester tester) async { - const AlertDialog dialog = AlertDialog( - actions: [ ], - content: SizedBox( - width: 1000.0, - height: 1000.0, - ), - ); - - tester.view.physicalSize = const Size(2000, 2000); - addTearDown(tester.view.resetPhysicalSize); - - await tester.pumpWidget(_buildAppWithDialog(dialog, theme: material3Theme)); - - await tester.tap(find.text('X')); - await tester.pumpAndSettle(); - - expect(_getDialogSize(tester), const Size(560.0, 560.0)); - }); - testWidgets('Simple dialog control test', (WidgetTester tester) async { await tester.pumpWidget( const MaterialApp( @@ -626,8 +593,15 @@ void main() { await tester.tap(find.text('X')); await tester.pumpAndSettle(); - - final Size dialogSize = _getDialogSize(tester); + // The [AlertDialog] is the entire screen, since it also contains the scrim. + // The first [Material] child of [AlertDialog] is the actual dialog + // itself. + final Size dialogSize = tester.getSize( + find.descendant( + of: find.byType(AlertDialog), + matching: find.byType(Material), + ).first, + ); final Size actionsSize = tester.getSize(_findButtonBar()); expect(actionsSize.width, dialogSize.width); @@ -655,7 +629,15 @@ void main() { await tester.tap(find.text('X')); await tester.pumpAndSettle(); - final Size dialogSize = _getDialogSize(tester); + // The [AlertDialog] is the entire screen, since it also contains the scrim. + // The first [Material] child of [AlertDialog] is the actual dialog + // itself. + final Size dialogSize = tester.getSize( + find.descendant( + of: find.byType(AlertDialog), + matching: find.byType(Material), + ).first, + ); final Size actionsSize = tester.getSize(find.byType(OverflowBar)); expect(actionsSize.width, dialogSize.width - (30.0 * 2)); diff --git a/packages/flutter/test/material/time_picker_test.dart b/packages/flutter/test/material/time_picker_test.dart index be79d70843c..4ecec0f2347 100644 --- a/packages/flutter/test/material/time_picker_test.dart +++ b/packages/flutter/test/material/time_picker_test.dart @@ -5,7 +5,6 @@ @TestOn('!chrome') library; -import 'dart:math'; import 'dart:ui'; import 'package:flutter/material.dart'; @@ -427,7 +426,7 @@ void main() { tester.view.devicePixelRatio = 1; await mediaQueryBoilerplate(tester, materialType: materialType); - width = min(timePickerPortraitSize.width + padding.horizontal, 560); // width is limited to 560 + width = timePickerPortraitSize.width + padding.horizontal; height = timePickerPortraitSize.height + padding.vertical; expect( tester.getSize(find.byWidget(getMaterialFromDialog(tester))), @@ -446,7 +445,7 @@ void main() { materialType: materialType, ); - width = min(timePickerLandscapeSize.width + padding.horizontal, 560); // width is limited to 560 + width = timePickerLandscapeSize.width + padding.horizontal; height = timePickerLandscapeSize.height + padding.vertical; expect( tester.getSize(find.byWidget(getMaterialFromDialog(tester))), @@ -750,10 +749,10 @@ void main() { expect(tester.getBottomLeft(find.text(okString)).dx, 616); expect(tester.getBottomRight(find.text(cancelString)).dx, 582); case MaterialType.material3: - expect(tester.getTopLeft(find.text(selectTimeString)), equals(const Offset(144, 129))); - expect(tester.getBottomRight(find.text(selectTimeString)), equals(const Offset(298.0, 143.0))); - expect(tester.getBottomLeft(find.text(okString)).dx, 610); - expect(tester.getBottomRight(find.text(cancelString)).dx, 572); + expect(tester.getTopLeft(find.text(selectTimeString)), equals(const Offset(138, 129))); + expect(tester.getBottomRight(find.text(selectTimeString)), equals(const Offset(292.0, 143.0))); + expect(tester.getBottomLeft(find.text(okString)).dx, 616); + expect(tester.getBottomRight(find.text(cancelString)).dx, 578); } await tester.tap(find.text(okString)); @@ -771,11 +770,11 @@ void main() { expect(tester.getBottomRight(find.text(okString)).dx, 184); expect(tester.getBottomLeft(find.text(cancelString)).dx, 218); case MaterialType.material3: - expect(tester.getTopLeft(find.text(selectTimeString)), equals(const Offset(502, 129))); - expect(tester.getBottomRight(find.text(selectTimeString)), equals(const Offset(656, 143))); - expect(tester.getBottomLeft(find.text(okString)).dx, 162); - expect(tester.getBottomRight(find.text(okString)).dx, 190); - expect(tester.getBottomLeft(find.text(cancelString)).dx, 228); + expect(tester.getTopLeft(find.text(selectTimeString)), equals(const Offset(508, 129))); + expect(tester.getBottomRight(find.text(selectTimeString)), equals(const Offset(662, 143))); + expect(tester.getBottomLeft(find.text(okString)).dx, 156); + expect(tester.getBottomRight(find.text(okString)).dx, 184); + expect(tester.getBottomLeft(find.text(cancelString)).dx, 222); } await tester.tap(find.text(okString));