diff --git a/packages/flutter/lib/src/widgets/text_selection.dart b/packages/flutter/lib/src/widgets/text_selection.dart index 4c2cbc43de..58097face0 100644 --- a/packages/flutter/lib/src/widgets/text_selection.dart +++ b/packages/flutter/lib/src/widgets/text_selection.dart @@ -853,7 +853,7 @@ class SelectionOverlay { _magnifierOverlayInfoBearer, ); - if (builtMagnifier == null || _handles == null) { + if (builtMagnifier == null) { return; } @@ -861,7 +861,7 @@ class SelectionOverlay { context: context, below: magnifierConfiguration.shouldDisplayHandlesInMagnifier ? null - : _handles!.first, + : _handles?.first, builder: (_) => builtMagnifier); } diff --git a/packages/flutter/test/widgets/text_selection_test.dart b/packages/flutter/test/widgets/text_selection_test.dart index 746f6c7a6c..3117ff5da2 100644 --- a/packages/flutter/test/widgets/text_selection_test.dart +++ b/packages/flutter/test/widgets/text_selection_test.dart @@ -1030,6 +1030,7 @@ void main() { ValueChanged? onEndDragEnd, VoidCallback? onSelectionHandleTapped, TextSelectionControls? selectionControls, + TextMagnifierConfiguration? magnifierConfiguration, }) async { final UniqueKey column = UniqueKey(); final LayerLink startHandleLayerLink = LayerLink(); @@ -1075,6 +1076,7 @@ void main() { selectionControls: selectionControls, selectionEndpoints: const [], toolbarLayerLink: toolbarLayerLink, + magnifierConfiguration: magnifierConfiguration ?? TextMagnifierConfiguration.disabled, ); } @@ -1279,6 +1281,35 @@ void main() { await tester.pump(const Duration(milliseconds: 20)); expect(endDragEndDetails, isNotNull); }); + + testWidgets('can show magnifier when no handles exist', (WidgetTester tester) async { + final GlobalKey magnifierKey = GlobalKey(); + final SelectionOverlay selectionOverlay = await pumpApp( + tester, + magnifierConfiguration: TextMagnifierConfiguration( + shouldDisplayHandlesInMagnifier: false, + magnifierBuilder: (BuildContext context, MagnifierController controller, ValueNotifier? notifier) { + return SizedBox.shrink( + key: magnifierKey, + ); + }, + ), + ); + + expect(find.byKey(magnifierKey), findsNothing); + + final MagnifierOverlayInfoBearer info = MagnifierOverlayInfoBearer( + globalGesturePosition: Offset.zero, + caretRect: Offset.zero & const Size(5.0, 20.0), + fieldBounds: Offset.zero & const Size(200.0, 50.0), + currentLineBoundaries: Offset.zero & const Size(200.0, 50.0), + ); + selectionOverlay.showMagnifier(info); + await tester.pump(); + + expect(tester.takeException(), isNull); + expect(find.byKey(magnifierKey), findsOneWidget); + }); }); group('ClipboardStatusNotifier', () {