@@ -408,6 +408,37 @@ class TextSelectionOverlay {
408
408
_selectionOverlay.showToolbar ();
409
409
}
410
410
411
+ /// {@macro flutter.widgets.SelectionOverlay.showMagnifier}
412
+ void showMagnifier (Offset positionToShow) {
413
+ final TextPosition position = renderObject.getPositionForPoint (positionToShow);
414
+ _updateSelectionOverlay ();
415
+ _selectionOverlay.showMagnifier (
416
+ _buildMagnifier (
417
+ currentTextPosition: position,
418
+ globalGesturePosition: positionToShow,
419
+ renderEditable: renderObject,
420
+ ),
421
+ );
422
+ }
423
+
424
+ /// {@macro flutter.widgets.SelectionOverlay.updateMagnifier}
425
+ void updateMagnifier (Offset positionToShow) {
426
+ final TextPosition position = renderObject.getPositionForPoint (positionToShow);
427
+ _updateSelectionOverlay ();
428
+ _selectionOverlay.updateMagnifier (
429
+ _buildMagnifier (
430
+ currentTextPosition: position,
431
+ globalGesturePosition: positionToShow,
432
+ renderEditable: renderObject,
433
+ ),
434
+ );
435
+ }
436
+
437
+ /// {@macro flutter.widgets.SelectionOverlay.hideMagnifier}
438
+ void hideMagnifier ({required bool shouldShowToolbar}) {
439
+ _selectionOverlay.hideMagnifier (shouldShowToolbar: shouldShowToolbar);
440
+ }
441
+
411
442
/// Updates the overlay after the selection has changed.
412
443
///
413
444
/// If this method is called while the [SchedulerBinding.schedulerPhase] is
@@ -457,6 +488,9 @@ class TextSelectionOverlay {
457
488
/// Whether the toolbar is currently visible.
458
489
bool get toolbarIsVisible => _selectionOverlay._toolbar != null ;
459
490
491
+ /// Whether the magnifier is currently visible.
492
+ bool get magnifierIsVisible => _selectionOverlay._magnifierController.shown;
493
+
460
494
/// {@macro flutter.widgets.SelectionOverlay.hide}
461
495
void hide () => _selectionOverlay.hide ();
462
496
@@ -554,11 +588,13 @@ class TextSelectionOverlay {
554
588
_dragEndPosition = details.globalPosition + Offset (0.0 , - handleSize.height);
555
589
final TextPosition position = renderObject.getPositionForPoint (_dragEndPosition);
556
590
557
- _selectionOverlay.showMagnifier (_buildMagnifier (
558
- currentTextPosition: position,
559
- globalGesturePosition: details.globalPosition,
560
- renderEditable: renderObject,
561
- ));
591
+ _selectionOverlay.showMagnifier (
592
+ _buildMagnifier (
593
+ currentTextPosition: position,
594
+ globalGesturePosition: details.globalPosition,
595
+ renderEditable: renderObject,
596
+ ),
597
+ );
562
598
}
563
599
564
600
void _handleSelectionEndHandleDragUpdate (DragUpdateDetails details) {
@@ -629,11 +665,13 @@ class TextSelectionOverlay {
629
665
_dragStartPosition = details.globalPosition + Offset (0.0 , - handleSize.height);
630
666
final TextPosition position = renderObject.getPositionForPoint (_dragStartPosition);
631
667
632
- _selectionOverlay.showMagnifier (_buildMagnifier (
633
- currentTextPosition: position,
634
- globalGesturePosition: details.globalPosition,
635
- renderEditable: renderObject,
636
- ));
668
+ _selectionOverlay.showMagnifier (
669
+ _buildMagnifier (
670
+ currentTextPosition: position,
671
+ globalGesturePosition: details.globalPosition,
672
+ renderEditable: renderObject,
673
+ ),
674
+ );
637
675
}
638
676
639
677
void _handleSelectionStartHandleDragUpdate (DragUpdateDetails details) {
@@ -788,6 +826,7 @@ class SelectionOverlay {
788
826
/// {@macro flutter.widgets.magnifier.TextMagnifierConfiguration.details}
789
827
final TextMagnifierConfiguration magnifierConfiguration;
790
828
829
+ /// {@template flutter.widgets.SelectionOverlay.showMagnifier}
791
830
/// Shows the magnifier, and hides the toolbar if it was showing when [showMagnifier]
792
831
/// was called. This is safe to call on platforms not mobile, since
793
832
/// a magnifierBuilder will not be provided, or the magnifierBuilder will return null
@@ -796,6 +835,7 @@ class SelectionOverlay {
796
835
/// This is NOT the source of truth for if the magnifier is up or not,
797
836
/// since magnifiers may hide themselves. If this info is needed, check
798
837
/// [MagnifierController.shown] .
838
+ /// {@endtemplate}
799
839
void showMagnifier (MagnifierOverlayInfoBearer initialInfoBearer) {
800
840
if (_toolbar != null ) {
801
841
hideToolbar ();
@@ -813,7 +853,7 @@ class SelectionOverlay {
813
853
_magnifierOverlayInfoBearer,
814
854
);
815
855
816
- if (builtMagnifier == null ) {
856
+ if (builtMagnifier == null || _handles == null ) {
817
857
return ;
818
858
}
819
859
@@ -825,10 +865,12 @@ class SelectionOverlay {
825
865
builder: (_) => builtMagnifier);
826
866
}
827
867
868
+ /// {@template flutter.widgets.SelectionOverlay.hideMagnifier}
828
869
/// Hide the current magnifier, optionally immediately showing
829
870
/// the toolbar.
830
871
///
831
872
/// This does nothing if there is no magnifier.
873
+ /// {@endtemplate}
832
874
void hideMagnifier ({required bool shouldShowToolbar}) {
833
875
// This cannot be a check on `MagnifierController.shown`, since
834
876
// it's possible that the magnifier is still in the overlay, but
@@ -1250,6 +1292,7 @@ class SelectionOverlay {
1250
1292
);
1251
1293
}
1252
1294
1295
+ /// {@template flutter.widgets.SelectionOverlay.updateMagnifier}
1253
1296
/// Update the current magnifier with new selection data, so the magnifier
1254
1297
/// can respond accordingly.
1255
1298
///
@@ -1258,6 +1301,7 @@ class SelectionOverlay {
1258
1301
/// itself.
1259
1302
///
1260
1303
/// If there is no magnifier in the overlay, this does nothing,
1304
+ /// {@endtemplate}
1261
1305
void updateMagnifier (MagnifierOverlayInfoBearer magnifierOverlayInfoBearer) {
1262
1306
if (_magnifierController.overlayEntry == null ) {
1263
1307
return ;
@@ -1919,6 +1963,18 @@ class TextSelectionGestureDetectorBuilder {
1919
1963
from: details.globalPosition,
1920
1964
cause: SelectionChangedCause .longPress,
1921
1965
);
1966
+
1967
+ switch (defaultTargetPlatform) {
1968
+ case TargetPlatform .android:
1969
+ case TargetPlatform .iOS:
1970
+ editableText.showMagnifier (details.globalPosition);
1971
+ break ;
1972
+ case TargetPlatform .fuchsia:
1973
+ case TargetPlatform .linux:
1974
+ case TargetPlatform .macOS:
1975
+ case TargetPlatform .windows:
1976
+ break ;
1977
+ }
1922
1978
}
1923
1979
}
1924
1980
@@ -1938,6 +1994,18 @@ class TextSelectionGestureDetectorBuilder {
1938
1994
from: details.globalPosition,
1939
1995
cause: SelectionChangedCause .longPress,
1940
1996
);
1997
+
1998
+ switch (defaultTargetPlatform) {
1999
+ case TargetPlatform .android:
2000
+ case TargetPlatform .iOS:
2001
+ editableText.showMagnifier (details.globalPosition);
2002
+ break ;
2003
+ case TargetPlatform .fuchsia:
2004
+ case TargetPlatform .linux:
2005
+ case TargetPlatform .macOS:
2006
+ case TargetPlatform .windows:
2007
+ break ;
2008
+ }
1941
2009
}
1942
2010
}
1943
2011
@@ -1951,6 +2019,17 @@ class TextSelectionGestureDetectorBuilder {
1951
2019
/// callback.
1952
2020
@protected
1953
2021
void onSingleLongTapEnd (LongPressEndDetails details) {
2022
+ switch (defaultTargetPlatform) {
2023
+ case TargetPlatform .android:
2024
+ case TargetPlatform .iOS:
2025
+ editableText.hideMagnifier (shouldShowToolbar: false );
2026
+ break ;
2027
+ case TargetPlatform .fuchsia:
2028
+ case TargetPlatform .linux:
2029
+ case TargetPlatform .macOS:
2030
+ case TargetPlatform .windows:
2031
+ break ;
2032
+ }
1954
2033
if (shouldShowSelectionToolbar) {
1955
2034
editableText.showToolbar ();
1956
2035
}
0 commit comments