Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7965ee2

Browse files
authored
Revert "Fix position of CupertinoContextMenu within Transform.scale (#97896)" (#102938)
This reverts commit 6ddb99e.
1 parent 6ddb99e commit 7965ee2

File tree

5 files changed

+13
-70
lines changed

5 files changed

+13
-70
lines changed

packages/flutter/lib/src/cupertino/context_menu.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ typedef _ContextMenuPreviewBuilderChildless = Widget Function(
4747
Rect _getRect(GlobalKey globalKey) {
4848
assert(globalKey.currentContext != null);
4949
final RenderBox renderBoxContainer = globalKey.currentContext!.findRenderObject()! as RenderBox;
50-
return Rect.fromPoints(renderBoxContainer.localToGlobal(
50+
final Offset containerOffset = renderBoxContainer.localToGlobal(
5151
renderBoxContainer.paintBounds.topLeft,
52-
), renderBoxContainer.localToGlobal(
53-
renderBoxContainer.paintBounds.bottomRight
54-
));
52+
);
53+
return containerOffset & renderBoxContainer.paintBounds.size;
5554
}
5655

5756
// The context menu arranges itself slightly differently based on the location

packages/flutter/test/cupertino/context_menu_test.dart

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -228,62 +228,6 @@ void main() {
228228
kIsWeb ? SystemMouseCursors.click : SystemMouseCursors.basic,
229229
);
230230
});
231-
232-
testWidgets('CupertinoContextMenu is in the correct position when within a Transform.scale', (WidgetTester tester) async {
233-
final Widget child = _getChild();
234-
await tester.pumpWidget(CupertinoApp(
235-
home: CupertinoPageScaffold(
236-
child: MediaQuery(
237-
data: const MediaQueryData(size: Size(800, 600)),
238-
child: Transform.scale(
239-
scale: 0.5,
240-
child: Align(
241-
//alignment: Alignment.bottomRight,
242-
child: CupertinoContextMenu(
243-
actions: const <CupertinoContextMenuAction>[
244-
CupertinoContextMenuAction(
245-
child: Text('CupertinoContextMenuAction'),
246-
),
247-
],
248-
child: child
249-
),
250-
)
251-
)
252-
)
253-
)
254-
));
255-
expect(find.byWidget(child), findsOneWidget);
256-
final Rect childRect = tester.getRect(find.byWidget(child));
257-
expect(find.byType(ShaderMask), findsNothing);
258-
259-
// Start a press on the child.
260-
final TestGesture gesture = await tester.startGesture(childRect.center);
261-
await tester.pump();
262-
263-
// The _DecoyChild is showing directly on top of the child.
264-
expect(_findDecoyChild(child), findsOneWidget);
265-
Rect decoyChildRect = tester.getRect(_findDecoyChild(child));
266-
expect(childRect, equals(decoyChildRect));
267-
268-
expect(find.byType(ShaderMask), findsOneWidget);
269-
270-
// After a small delay, the _DecoyChild has begun to animate.
271-
await tester.pump(const Duration(milliseconds: 100));
272-
decoyChildRect = tester.getRect(_findDecoyChild(child));
273-
expect(childRect, isNot(equals(decoyChildRect)));
274-
275-
// Eventually the decoy fully scales by _kOpenSize.
276-
await tester.pump(const Duration(milliseconds: 500));
277-
decoyChildRect = tester.getRect(_findDecoyChild(child));
278-
expect(childRect, isNot(equals(decoyChildRect)));
279-
expect(decoyChildRect.width, childRect.width * kOpenScale);
280-
281-
// Then the CupertinoContextMenu opens.
282-
await tester.pumpAndSettle();
283-
await gesture.up();
284-
await tester.pumpAndSettle();
285-
expect(_findStatic(), findsOneWidget);
286-
});
287231
});
288232

289233
group('CupertinoContextMenu when open', () {

packages/flutter/test/material/flexible_space_bar_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ void main() {
473473
Rect.fromLTRB(
474474
0,
475475
height - titleFontSize - 10,
476-
(width / 1.5).floorToDouble() * 1.5,
477-
height,
476+
(width / 1.5).floorToDouble(),
477+
height - 10,
478478
),
479479
);
480480
});
@@ -545,8 +545,8 @@ void main() {
545545
Rect.fromLTRB(
546546
0,
547547
height - titleFontSize - bottomMargin,
548-
(collapsedWidth / 3).floorToDouble() * 3,
549-
height,
548+
(collapsedWidth / 3).floorToDouble(),
549+
height - bottomMargin,
550550
),
551551
);
552552
});

packages/flutter/test/material/input_decorator_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4321,17 +4321,17 @@ void main() {
43214321
await pumpDecorator(focused: false, empty: false);
43224322
await tester.pumpAndSettle();
43234323
expect(getLabelRect(tester).topLeft, equals(const Offset(12, -5.5)));
4324-
expect(getLabelRect(tester).size, equals(const Size(80, 16) * 0.75));
4324+
expect(getLabelRect(tester).size, equals(const Size(80, 16)));
43254325

43264326
await pumpDecorator(focused: true);
43274327
await tester.pumpAndSettle();
43284328
expect(getLabelRect(tester).topLeft, equals(const Offset(12, -5.5)));
4329-
expect(getLabelRect(tester).size, equals(const Size(80, 16) * 0.75));
4329+
expect(getLabelRect(tester).size, equals(const Size(80, 16)));
43304330

43314331
await pumpDecorator(focused: true, empty: false);
43324332
await tester.pumpAndSettle();
43334333
expect(getLabelRect(tester).topLeft, equals(const Offset(12, -5.5)));
4334-
expect(getLabelRect(tester).size, equals(const Size(80, 16) * 0.75));
4334+
expect(getLabelRect(tester).size, equals(const Size(80, 16)));
43354335

43364336
await pumpDecorator(focused: false, enabled: false);
43374337
await tester.pumpAndSettle();
@@ -4341,7 +4341,7 @@ void main() {
43414341
await pumpDecorator(focused: false, empty: false, enabled: false);
43424342
await tester.pumpAndSettle();
43434343
expect(getLabelRect(tester).topLeft, equals(const Offset(12, -5.5)));
4344-
expect(getLabelRect(tester).size, equals(const Size(80, 16) * 0.75));
4344+
expect(getLabelRect(tester).size, equals(const Size(80, 16)));
43454345

43464346
// Focused and disabled happens with NavigationMode.directional.
43474347
await pumpDecorator(focused: true, enabled: false);
@@ -4352,7 +4352,7 @@ void main() {
43524352
await pumpDecorator(focused: true, empty: false, enabled: false);
43534353
await tester.pumpAndSettle();
43544354
expect(getLabelRect(tester).topLeft, equals(const Offset(12, -5.5)));
4355-
expect(getLabelRect(tester).size, equals(const Size(80, 16) * 0.75));
4355+
expect(getLabelRect(tester).size, equals(const Size(80, 16)));
43564356
});
43574357

43584358
testWidgets('InputDecorationTheme.toString()', (WidgetTester tester) async {

packages/flutter_test/lib/src/controller.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ abstract class WidgetController {
11381138

11391139
/// Returns the rect of the given widget. This is only valid once
11401140
/// the widget's render object has been laid out at least once.
1141-
Rect getRect(Finder finder) => Rect.fromPoints(getTopLeft(finder), getBottomRight(finder));
1141+
Rect getRect(Finder finder) => getTopLeft(finder) & getSize(finder);
11421142

11431143
/// Attempts to find the [SemanticsNode] of first result from `finder`.
11441144
///

0 commit comments

Comments
 (0)