Unverified Commit 1fbd7ec1 authored by fzyzcjy's avatar fzyzcjy Committed by GitHub

Fix CupertinoAlertDialog and CupertinoActionSheet, which mis-behave when...

Fix CupertinoAlertDialog and CupertinoActionSheet, which mis-behave when orientation changes (#112041)
parent a5dc49f4
......@@ -696,14 +696,14 @@ class _DayPeriodInputPadding extends SingleChildRenderObjectWidget {
@override
void updateRenderObject(BuildContext context, covariant _RenderInputPadding renderObject) {
renderObject.minSize = minSize;
renderObject
..minSize = minSize
..orientation = orientation;
}
}
class _RenderInputPadding extends RenderShiftedBox {
_RenderInputPadding(this._minSize, this.orientation, [RenderBox? child]) : super(child);
final Orientation orientation;
_RenderInputPadding(this._minSize, this._orientation, [RenderBox? child]) : super(child);
Size get minSize => _minSize;
Size _minSize;
......@@ -715,6 +715,16 @@ class _RenderInputPadding extends RenderShiftedBox {
markNeedsLayout();
}
Orientation get orientation => _orientation;
Orientation _orientation;
set orientation(Orientation value) {
if (_orientation == value) {
return;
}
_orientation = value;
markNeedsLayout();
}
@override
double computeMinIntrinsicWidth(double height) {
if (child != null) {
......
......@@ -612,6 +612,27 @@ void _tests() {
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 {
Widget buildFrame(TextDirection textDirection) {
return MaterialApp(
......@@ -1342,6 +1363,7 @@ Future<void> mediaQueryBoilerplate(
String? errorInvalidText,
bool accessibleNavigation = false,
EntryModeChangeCallback? onEntryModeChange,
bool tapButton = true,
}) async {
await tester.pumpWidget(
Localizations(
......@@ -1355,6 +1377,7 @@ Future<void> mediaQueryBoilerplate(
alwaysUse24HourFormat: alwaysUse24HourFormat,
textScaleFactor: textScaleFactor,
accessibleNavigation: accessibleNavigation,
size: tester.binding.window.physicalSize / tester.binding.window.devicePixelRatio,
),
child: Material(
child: Directionality(
......@@ -1385,6 +1408,8 @@ Future<void> mediaQueryBoilerplate(
),
),
);
await tester.tap(find.text('X'));
if (tapButton) {
await tester.tap(find.text('X'));
}
await tester.pumpAndSettle();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment