@@ -15,19 +15,17 @@ import 'inherited_theme.dart';
1515import 'navigator.dart' ;
1616import 'overlay.dart' ;
1717
18- /// {@template flutter.widgets.magnifier.MagnifierBuilder}
1918/// Signature for a builder that builds a [Widget] with a [MagnifierController] .
2019///
21- /// Consuming [MagnifierController] or [ValueNotifier] <[MagnifierInfo] > is not
22- /// required, although if a Widget intends to have entry or exit animations, it should take
23- /// [MagnifierController] and provide it an [AnimationController] , so that [MagnifierController]
24- /// can wait before removing it from the overlay.
25- /// {@endtemplate}
20+ /// The builder is called exactly once per magnifier.
2621///
27- /// See also:
22+ /// If the `controller` parameter's [MagnifierController.animationController]
23+ /// field is set (by the builder) to an [AnimationController] , the
24+ /// [MagnifierController] will drive the animation during entry and exit.
2825///
29- /// - [MagnifierInfo] , the data class that updates the
30- /// magnifier.
26+ /// The `magnifierInfo` parameter is updated with new [MagnifierInfo] instances
27+ /// during the lifetime of the built magnifier, e.g. as the user moves their
28+ /// finger around the text field.
3129typedef MagnifierBuilder = Widget ? Function (
3230 BuildContext context,
3331 MagnifierController controller,
@@ -57,9 +55,9 @@ class MagnifierInfo {
5755 /// The offset of the gesture position that the magnifier should be shown at.
5856 final Offset globalGesturePosition;
5957
60- /// The rect of the current line the magnifier should be shown at,
61- /// without taking into account any padding of the field; only the position
62- /// of the first and last character.
58+ /// The rect of the current line the magnifier should be shown at, without
59+ /// taking into account any padding of the field; only the position of the
60+ /// first and last character.
6361 final Rect currentLineBoundaries;
6462
6563 /// The rect of the handle that the magnifier should follow.
@@ -89,48 +87,45 @@ class MagnifierInfo {
8987 );
9088}
9189
92- /// {@template flutter.widgets.magnifier.TextMagnifierConfiguration.intro}
93- /// A configuration object for a magnifier.
94- /// {@endtemplate}
90+ /// A configuration object for a magnifier (e.g. in a text field).
9591///
96- /// {@macro flutter.widgets.magnifier.intro}
97- ///
98- /// {@template flutter.widgets.magnifier.TextMagnifierConfiguration.details}
99- /// In general, most features of the magnifier can be configured through
100- /// [MagnifierBuilder] . [TextMagnifierConfiguration] is used to configure
101- /// the magnifier's behavior through the [SelectionOverlay] .
102- /// {@endtemplate}
92+ /// In general, most features of the magnifier can be configured by controlling
93+ /// the widgets built by the [magnifierBuilder] .
10394class TextMagnifierConfiguration {
10495 /// Constructs a [TextMagnifierConfiguration] from parts.
10596 ///
10697 /// If [magnifierBuilder] is null, a default [MagnifierBuilder] will be used
107- /// that never builds a magnifier.
98+ /// that does not build a magnifier.
10899 const TextMagnifierConfiguration ({
109100 MagnifierBuilder ? magnifierBuilder,
110- this .shouldDisplayHandlesInMagnifier = true
101+ this .shouldDisplayHandlesInMagnifier = true ,
111102 }) : _magnifierBuilder = magnifierBuilder;
112103
113- /// The passed in [MagnifierBuilder] .
114- ///
115- /// This is nullable because [disabled] needs to be static const,
116- /// so that it can be used as a default parameter. If left null,
117- /// the [magnifierBuilder] getter will be a function that always returns
118- /// null.
104+ /// The builder callback that creates the widget that renders the magnifier.
105+ MagnifierBuilder get magnifierBuilder => _magnifierBuilder ?? _none;
119106 final MagnifierBuilder ? _magnifierBuilder;
120107
121- /// {@macro flutter.widgets.magnifier.MagnifierBuilder}
122- MagnifierBuilder get magnifierBuilder => _magnifierBuilder ?? (_, __, ___) => null ;
108+ static Widget ? _none (
109+ BuildContext context,
110+ MagnifierController controller,
111+ ValueNotifier <MagnifierInfo > magnifierInfo,
112+ ) => null ;
123113
124- /// Determines whether a magnifier should show the text editing handles or not.
114+ /// Whether a magnifier should show the text editing handles or not.
115+ ///
116+ /// This flag is used by [SelectionOverlay.showMagnifier] to control the order
117+ /// of layers in the rendering; specifically, whether to place the layer
118+ /// containing the handles above or below the layer containing the magnifier
119+ /// in the [Overlay] .
125120 final bool shouldDisplayHandlesInMagnifier;
126121
127- /// A constant for a [TextMagnifierConfiguration] that is disabled.
128- ///
129- /// In particular, this [TextMagnifierConfiguration] is considered disabled
130- /// because it never builds anything, regardless of platform.
122+ /// A constant for a [TextMagnifierConfiguration] that is disabled, meaning it
123+ /// never builds anything, regardless of platform.
131124 static const TextMagnifierConfiguration disabled = TextMagnifierConfiguration ();
132125}
133126
127+ /// A controller for a magnifier.
128+ ///
134129/// [MagnifierController] 's main benefit over holding a raw [OverlayEntry] is that
135130/// [MagnifierController] will handle logic around waiting for a magnifier to animate in or out.
136131///
@@ -156,11 +151,11 @@ class MagnifierController {
156151
157152 /// The magnifier's [OverlayEntry] , if currently in the overlay.
158153 ///
159- /// This is public in case other overlay entries need to be positioned
160- /// above or below this [overlayEntry] . Anything in the paint order after
161- /// the [RawMagnifier] will not be displayed in the magnifier; this means that if it
162- /// is desired for an overlay entry to be displayed in the magnifier,
163- /// it _must_ be positioned below the magnifier.
154+ /// This is exposed so that other overlay entries can be positioned above or
155+ /// below this [overlayEntry] . Anything in the paint order after the
156+ /// [RawMagnifier] in this [OverlayEntry] will not be displayed in the
157+ /// magnifier; if it is desired for an overlay entry to be displayed in the
158+ /// magnifier, it _must_ be positioned below the magnifier.
164159 ///
165160 /// {@tool snippet}
166161 /// ```dart
@@ -198,20 +193,22 @@ class MagnifierController {
198193 /// ```
199194 /// {@end-tool}
200195 ///
201- /// A null check on [overlayEntry] will not suffice to check if a magnifier is in the
202- /// overlay or not; instead, you should check [shown] . This is because it is possible,
203- /// such as in cases where [hide] was called with `removeFromOverlay` false, that the magnifier
204- /// is not shown, but the entry is not null.
196+ /// To check if a magnifier is in the overlay, use [shown] . The [overlayEntry]
197+ /// field may be non-null even when the magnifier is not visible.
205198 OverlayEntry ? get overlayEntry => _overlayEntry;
206199 OverlayEntry ? _overlayEntry;
207200
208- /// If the magnifier is shown or not.
201+ /// Whether the magnifier is currently being shown.
202+ ///
203+ /// This is false when nothing is in the overlay, when the
204+ /// [animationController] is in the [AnimationStatus.dismissed] state, or when
205+ /// the [animationController] is animating out (i.e. in the
206+ /// [AnimationStatus.reverse] state).
209207 ///
210- /// [shown] is:
211- /// - false when nothing is in the overlay.
212- /// - false when [animationController] is [AnimationStatus.dismissed] .
213- /// - false when [animationController] is animating out.
214- /// and true in all other circumstances.
208+ /// It is true in the opposite cases, i.e. when the overlay is not empty, and
209+ /// either the [animationController] is null, in the
210+ /// [AnimationStatus.completed] state, or in the [AnimationStatus.forward]
211+ /// state.
215212 bool get shown {
216213 if (overlayEntry == null ) {
217214 return false ;
@@ -225,17 +222,17 @@ class MagnifierController {
225222 return true ;
226223 }
227224
228- /// Shows the [RawMagnifier] that this controller controls .
225+ /// Displays the magnifier .
229226 ///
230227 /// Returns a future that completes when the magnifier is fully shown, i.e. done
231228 /// with its entry animation.
232229 ///
233- /// To control what overlays are shown in the magnifier, utilize [ below] . See
234- /// [overlayEntry] for more details on how to utilize [ below] .
230+ /// To control what overlays are shown in the magnifier, use ` below` . See
231+ /// [overlayEntry] for more details on how to utilize ` below` .
235232 ///
236- /// If the magnifier already exists (i.e. [overlayEntry] != null), then [show] will
237- /// override the old overlay and not play an exit animation. Consider awaiting [hide]
238- /// first, to guarantee
233+ /// If the magnifier already exists (i.e. [overlayEntry] != null), then [show]
234+ /// will replace the old overlay without playing an exit animation. Consider
235+ /// awaiting [hide] first, to animate from the old magnifier to the new one.
239236 Future <void > show ({
240237 required BuildContext context,
241238 required WidgetBuilder builder,
0 commit comments