Revert "Provide default constraints for M3 dialogs" (#126355) (#126368) (#126493)

Reverts flutter/flutter#120082

Causing breakages: b/281181985

*Replace this paragraph with a description of what this PR is changing
or adding, and why. Consider including before/after screenshots.*

*List which issues are fixed by this PR. You must list at least one
issue.*

*If you had to change anything in the [flutter/tests] repo, include a
link to the migration guide as per the [breaking change policy].*

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree
Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter
Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[Features we expect every widget to implement]:

https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:

https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat

*Replace this paragraph with a description of what this PR is changing
or adding, and why. Consider including before/after screenshots.*

*List which issues are fixed by this PR. You must list at least one
issue.*

*If you had to change anything in the [flutter/tests] repo, include a
link to the migration guide as per the [breaking change policy].*

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
Kevin Chisholm 2023-05-10 22:17:44 -05:00 committed by GitHub
parent 65dfb555c0
commit 979205ff40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 63 deletions

View File

@ -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)

View File

@ -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: <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(
@ -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));

View File

@ -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));