Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Provide default constraints for M3 dialogs" #126355

Merged
merged 1 commit into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 2 additions & 15 deletions packages/flutter/lib/src/material/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
54 changes: 18 additions & 36 deletions packages/flutter/test/material/dialog_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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: <Widget>[ ],
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(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
23 changes: 11 additions & 12 deletions packages/flutter/test/material/time_picker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
@TestOn('!chrome')
library;

import 'dart:math';
import 'dart:ui';

import 'package:flutter/material.dart';
Expand Down Expand Up @@ -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))),
Expand All @@ -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))),
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down