diff --git a/packages/flutter/lib/src/rendering/paragraph.dart b/packages/flutter/lib/src/rendering/paragraph.dart index acdfed2543..13b17af303 100644 --- a/packages/flutter/lib/src/rendering/paragraph.dart +++ b/packages/flutter/lib/src/rendering/paragraph.dart @@ -388,6 +388,9 @@ class RenderParagraph extends RenderBox with ContainerRenderObjectMixin _lastSelectableFragments?.isNotEmpty ?? false; + @override void markNeedsLayout() { _lastSelectableFragments?.forEach((_SelectableFragment element) => element.didChangeParagraphLayout()); diff --git a/packages/flutter/test/material/selection_area_test.dart b/packages/flutter/test/material/selection_area_test.dart index 8e786831dc..1a61612b64 100644 --- a/packages/flutter/test/material/selection_area_test.dart +++ b/packages/flutter/test/material/selection_area_test.dart @@ -70,6 +70,63 @@ void main() { expect(tester.takeException(), isNull); }); + // Regression test for https://github.com/flutter/flutter/issues/111370 + testWidgetsWithLeakTracking('Handle is correctly transformed when the text is inside of a FittedBox ',(WidgetTester tester) async { + final Key textKey = UniqueKey(); + await tester.pumpWidget( + MaterialApp( + color: const Color(0xFF2196F3), + home: Scaffold( + body: SelectionArea( + child: SizedBox( + height: 100, + child: FittedBox( + fit: BoxFit.fill, + child: Text('test', key: textKey), + ), + ), + ), + ), + ), + ); + + final TestGesture longpress = await tester.startGesture(const Offset(10, 10)); + addTearDown(longpress.removePointer); + await tester.pump(const Duration(milliseconds: 500)); + await longpress.up(); + + // Text box is scaled by 5. + final RenderBox textBox = tester.firstRenderObject(find.byKey(textKey)); + expect(textBox.size.height, 20.0); + final Offset textPoint = textBox.localToGlobal(const Offset(0, 20)); + expect(textPoint, equals(const Offset(0, 100))); + + // Find handles and verify their sizes. + expect(find.byType(Overlay), findsOneWidget); + expect(find.descendant(of: find.byType(Overlay),matching: find.byType(CustomPaint),),findsNWidgets(2)); + final Iterable handles = tester.renderObjectList(find.descendant( + of: find.byType(Overlay), + matching: find.byType(CustomPaint), + )); + + // The handle height is determined by the formula: + // textLineHeight + _kSelectionHandleRadius * 2 - _kSelectionHandleOverlap . + // The text line height will be the value of the fontSize. + // The constant _kSelectionHandleRadius has the value of 6. + // The constant _kSelectionHandleOverlap has the value of 1.5. + // The handle height before scaling is 20.0 + 6 * 2 - 1.5 = 30.5. + + final double handleHeightBeforeScaling = handles.first.size.height; + expect(handleHeightBeforeScaling, 30.5); + + final Offset handleHeightAfterScaling = handles.first.localToGlobal(const Offset(0, 30.5)) - handles.first.localToGlobal(Offset.zero); + + // The handle height after scaling is 30.5 * 5 = 152.5 + expect(handleHeightAfterScaling, equals(const Offset(0.0, 152.5))); + }, + skip: isBrowser, // [intended] + variant: const TargetPlatformVariant({TargetPlatform.iOS}), + ); testWidgetsWithLeakTracking('builds the default context menu by default', (WidgetTester tester) async { final FocusNode focusNode = FocusNode();