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
|
||||
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(
|
||||
),
|
||||
),
|
||||
);
|
||||
if (tapButton) {
|
||||
await tester.tap(find.text('X'));
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user