Fix CupertinoAlertDialog and CupertinoActionSheet, which mis-behave when orientation changes (#112041)
This commit is contained in:
parent
a5dc49f4da
commit
1fbd7ec117
@ -696,14 +696,14 @@ class _DayPeriodInputPadding extends SingleChildRenderObjectWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void updateRenderObject(BuildContext context, covariant _RenderInputPadding renderObject) {
|
void updateRenderObject(BuildContext context, covariant _RenderInputPadding renderObject) {
|
||||||
renderObject.minSize = minSize;
|
renderObject
|
||||||
|
..minSize = minSize
|
||||||
|
..orientation = orientation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _RenderInputPadding extends RenderShiftedBox {
|
class _RenderInputPadding extends RenderShiftedBox {
|
||||||
_RenderInputPadding(this._minSize, this.orientation, [RenderBox? child]) : super(child);
|
_RenderInputPadding(this._minSize, this._orientation, [RenderBox? child]) : super(child);
|
||||||
|
|
||||||
final Orientation orientation;
|
|
||||||
|
|
||||||
Size get minSize => _minSize;
|
Size get minSize => _minSize;
|
||||||
Size _minSize;
|
Size _minSize;
|
||||||
@ -715,6 +715,16 @@ class _RenderInputPadding extends RenderShiftedBox {
|
|||||||
markNeedsLayout();
|
markNeedsLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Orientation get orientation => _orientation;
|
||||||
|
Orientation _orientation;
|
||||||
|
set orientation(Orientation value) {
|
||||||
|
if (_orientation == value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_orientation = value;
|
||||||
|
markNeedsLayout();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
double computeMinIntrinsicWidth(double height) {
|
double computeMinIntrinsicWidth(double height) {
|
||||||
if (child != null) {
|
if (child != null) {
|
||||||
|
@ -612,6 +612,27 @@ void _tests() {
|
|||||||
tester.binding.window.clearDevicePixelRatioTestValue();
|
tester.binding.window.clearDevicePixelRatioTestValue();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('when change orientation, should reflect in render objects', (WidgetTester tester) async {
|
||||||
|
// portrait
|
||||||
|
tester.binding.window.physicalSizeTestValue = const Size(800, 800.5);
|
||||||
|
tester.binding.window.devicePixelRatioTestValue = 1;
|
||||||
|
await mediaQueryBoilerplate(tester, false);
|
||||||
|
|
||||||
|
RenderObject render = tester.renderObject(find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_DayPeriodInputPadding'));
|
||||||
|
expect((render as dynamic).orientation, Orientation.portrait); // ignore: avoid_dynamic_calls
|
||||||
|
|
||||||
|
// landscape
|
||||||
|
tester.binding.window.physicalSizeTestValue = const Size(800.5, 800);
|
||||||
|
tester.binding.window.devicePixelRatioTestValue = 1;
|
||||||
|
await mediaQueryBoilerplate(tester, false, tapButton: false);
|
||||||
|
|
||||||
|
render = tester.renderObject(find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_DayPeriodInputPadding'));
|
||||||
|
expect((render as dynamic).orientation, Orientation.landscape); // ignore: avoid_dynamic_calls
|
||||||
|
|
||||||
|
tester.binding.window.clearPhysicalSizeTestValue();
|
||||||
|
tester.binding.window.clearDevicePixelRatioTestValue();
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('builder parameter', (WidgetTester tester) async {
|
testWidgets('builder parameter', (WidgetTester tester) async {
|
||||||
Widget buildFrame(TextDirection textDirection) {
|
Widget buildFrame(TextDirection textDirection) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
@ -1342,6 +1363,7 @@ Future<void> mediaQueryBoilerplate(
|
|||||||
String? errorInvalidText,
|
String? errorInvalidText,
|
||||||
bool accessibleNavigation = false,
|
bool accessibleNavigation = false,
|
||||||
EntryModeChangeCallback? onEntryModeChange,
|
EntryModeChangeCallback? onEntryModeChange,
|
||||||
|
bool tapButton = true,
|
||||||
}) async {
|
}) async {
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
Localizations(
|
Localizations(
|
||||||
@ -1355,6 +1377,7 @@ Future<void> mediaQueryBoilerplate(
|
|||||||
alwaysUse24HourFormat: alwaysUse24HourFormat,
|
alwaysUse24HourFormat: alwaysUse24HourFormat,
|
||||||
textScaleFactor: textScaleFactor,
|
textScaleFactor: textScaleFactor,
|
||||||
accessibleNavigation: accessibleNavigation,
|
accessibleNavigation: accessibleNavigation,
|
||||||
|
size: tester.binding.window.physicalSize / tester.binding.window.devicePixelRatio,
|
||||||
),
|
),
|
||||||
child: Material(
|
child: Material(
|
||||||
child: Directionality(
|
child: Directionality(
|
||||||
@ -1385,6 +1408,8 @@ Future<void> mediaQueryBoilerplate(
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
if (tapButton) {
|
||||||
await tester.tap(find.text('X'));
|
await tester.tap(find.text('X'));
|
||||||
|
}
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user