Unverified Commit 8f9a5195 authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

Fix Magnifier crash (#111303)

parent 52af1a51
...@@ -853,7 +853,7 @@ class SelectionOverlay { ...@@ -853,7 +853,7 @@ class SelectionOverlay {
_magnifierOverlayInfoBearer, _magnifierOverlayInfoBearer,
); );
if (builtMagnifier == null || _handles == null) { if (builtMagnifier == null) {
return; return;
} }
...@@ -861,7 +861,7 @@ class SelectionOverlay { ...@@ -861,7 +861,7 @@ class SelectionOverlay {
context: context, context: context,
below: magnifierConfiguration.shouldDisplayHandlesInMagnifier below: magnifierConfiguration.shouldDisplayHandlesInMagnifier
? null ? null
: _handles!.first, : _handles?.first,
builder: (_) => builtMagnifier); builder: (_) => builtMagnifier);
} }
......
...@@ -1030,6 +1030,7 @@ void main() { ...@@ -1030,6 +1030,7 @@ void main() {
ValueChanged<DragEndDetails>? onEndDragEnd, ValueChanged<DragEndDetails>? onEndDragEnd,
VoidCallback? onSelectionHandleTapped, VoidCallback? onSelectionHandleTapped,
TextSelectionControls? selectionControls, TextSelectionControls? selectionControls,
TextMagnifierConfiguration? magnifierConfiguration,
}) async { }) async {
final UniqueKey column = UniqueKey(); final UniqueKey column = UniqueKey();
final LayerLink startHandleLayerLink = LayerLink(); final LayerLink startHandleLayerLink = LayerLink();
...@@ -1075,6 +1076,7 @@ void main() { ...@@ -1075,6 +1076,7 @@ void main() {
selectionControls: selectionControls, selectionControls: selectionControls,
selectionEndpoints: const <TextSelectionPoint>[], selectionEndpoints: const <TextSelectionPoint>[],
toolbarLayerLink: toolbarLayerLink, toolbarLayerLink: toolbarLayerLink,
magnifierConfiguration: magnifierConfiguration ?? TextMagnifierConfiguration.disabled,
); );
} }
...@@ -1279,6 +1281,35 @@ void main() { ...@@ -1279,6 +1281,35 @@ void main() {
await tester.pump(const Duration(milliseconds: 20)); await tester.pump(const Duration(milliseconds: 20));
expect(endDragEndDetails, isNotNull); 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<MagnifierOverlayInfoBearer>? 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', () { group('ClipboardStatusNotifier', () {
......
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