@@ -56,15 +56,6 @@ typedef _DismissCallback = void Function(
56
56
double opacity,
57
57
);
58
58
59
- /// A function that produces the preview when the CupertinoContextMenu is open.
60
- ///
61
- /// Called every time the animation value changes.
62
- typedef ContextMenuPreviewBuilder = Widget Function (
63
- BuildContext context,
64
- Animation <double > animation,
65
- Widget child,
66
- );
67
-
68
59
/// A function that builds the child and handles the transition between the
69
60
/// default child and the preview when the CupertinoContextMenu is open.
70
61
typedef CupertinoContextMenuBuilder = Widget Function (
@@ -95,23 +86,17 @@ enum _ContextMenuLocation {
95
86
96
87
/// A full-screen modal route that opens when the [child] is long-pressed.
97
88
///
98
- /// When open, the [CupertinoContextMenu] shows the child, or the widget returned
99
- /// by [previewBuilder] if given, in a large full-screen [Overlay] with a list
100
- /// of buttons specified by [actions] . The child/preview is placed in an
101
- /// [Expanded] widget so that it will grow to fill the Overlay if its size is
102
- /// unconstrained.
89
+ /// When open, the [CupertinoContextMenu] shows the child in a large full-screen
90
+ /// [Overlay] with a list of buttons specified by [actions] . The child/preview is
91
+ /// placed in an [Expanded] widget so that it will grow to fill the Overlay if
92
+ /// its size is unconstrained.
103
93
///
104
94
/// When closed, the [CupertinoContextMenu] displays the child as if the
105
95
/// [CupertinoContextMenu] were not there. Sizing and positioning is unaffected.
106
96
/// The menu can be closed like other [PopupRoute] s, such as by tapping the
107
97
/// background or by calling `Navigator.pop(context)` . Unlike [PopupRoute] , it can
108
98
/// also be closed by swiping downwards.
109
99
///
110
- /// The [previewBuilder] parameter is most commonly used to display a slight
111
- /// variation of [child] . See [previewBuilder] for an example of rounding the
112
- /// child's corners and allowing its aspect ratio to expand, similar to the
113
- /// Photos app on iOS.
114
- ///
115
100
/// {@tool dartpad}
116
101
/// This sample shows a very simple [CupertinoContextMenu] for the Flutter logo.
117
102
/// Long press on it to open.
@@ -138,11 +123,6 @@ class CupertinoContextMenu extends StatefulWidget {
138
123
required this .actions,
139
124
required Widget this .child,
140
125
this .enableHapticFeedback = false ,
141
- @Deprecated (
142
- 'Use CupertinoContextMenu.builder instead. '
143
- 'This feature was deprecated after v3.4.0-34.1.pre.' ,
144
- )
145
- this .previewBuilder = _defaultPreviewBuilder,
146
126
}) : assert (actions.isNotEmpty),
147
127
builder = ((BuildContext context, Animation <double > animation) => child);
148
128
@@ -158,8 +138,7 @@ class CupertinoContextMenu extends StatefulWidget {
158
138
required this .builder,
159
139
this .enableHapticFeedback = false ,
160
140
}) : assert (actions.isNotEmpty),
161
- child = null ,
162
- previewBuilder = null ;
141
+ child = null ;
163
142
164
143
/// Exposes the default border radius for matching iOS 16.0 behavior. This
165
144
/// value was eyeballed from the iOS simulator running iOS 16.0.
@@ -353,28 +332,14 @@ class CupertinoContextMenu extends StatefulWidget {
353
332
/// {@end-tool}
354
333
final CupertinoContextMenuBuilder builder;
355
334
356
- /// The default preview builder if none is provided. It makes a rectangle
357
- /// around the child widget with rounded borders, matching the iOS 16 opened
358
- /// context menu eyeballed on the XCode iOS simulator.
359
- static Widget _defaultPreviewBuilder (BuildContext context, Animation <double > animation, Widget child) {
360
- return FittedBox (
361
- fit: BoxFit .cover,
362
- child: ClipRRect (
363
- borderRadius: BorderRadius .circular (_previewBorderRadiusRatio * animation.value),
364
- child: child,
365
- ),
366
- );
367
- }
368
-
369
335
// TODO(mitchgoodwin): deprecate [child] with builder refactor https://github.com/flutter/flutter/issues/116306
370
336
371
337
/// The widget that can be "opened" with the [CupertinoContextMenu] .
372
338
///
373
339
/// When the [CupertinoContextMenu] is long-pressed, the menu will open and
374
- /// this widget (or the widget returned by [previewBuilder] , if provided) will
375
- /// be moved to the new route and placed inside of an [Expanded] widget. This
376
- /// allows the child to resize to fit in its place in the new route, if it
377
- /// doesn't size itself.
340
+ /// this widget will be moved to the new route and placed inside of an
341
+ /// [Expanded] widget. This allows the child to resize to fit in its place in
342
+ /// the new route, if it doesn't size itself.
378
343
///
379
344
/// When the [CupertinoContextMenu] is "closed", this widget acts like a
380
345
/// [Container] , i.e. it does not constrain its child's size or affect its
@@ -395,73 +360,6 @@ class CupertinoContextMenu extends StatefulWidget {
395
360
/// Defaults to false.
396
361
final bool enableHapticFeedback;
397
362
398
- /// A function that returns an alternative widget to show when the
399
- /// [CupertinoContextMenu] is open.
400
- ///
401
- /// If not specified, [child] will be shown.
402
- ///
403
- /// The preview is often used to show a slight variation of the [child] . For
404
- /// example, the child could be given rounded corners in the preview but have
405
- /// sharp corners when in the page.
406
- ///
407
- /// In addition to the current [BuildContext] , the function is also called
408
- /// with an [Animation] and the [child] . The animation goes from 0 to 1 when
409
- /// the CupertinoContextMenu opens, and from 1 to 0 when it closes, and it can
410
- /// be used to animate the preview in sync with this opening and closing. The
411
- /// child parameter provides access to the child displayed when the
412
- /// CupertinoContextMenu is closed.
413
- ///
414
- /// {@tool snippet}
415
- ///
416
- /// Below is an example of using [previewBuilder] to show an image tile that's
417
- /// similar to each tile in the iOS iPhoto app's context menu. Several of
418
- /// these could be used in a GridView for a similar effect.
419
- ///
420
- /// When opened, the child animates to show its full aspect ratio and has
421
- /// rounded corners. The larger size of the open CupertinoContextMenu allows
422
- /// the FittedBox to fit the entire image, even when it has a very tall or
423
- /// wide aspect ratio compared to the square of a GridView, so this animates
424
- /// into view as the CupertinoContextMenu is opened. The preview is swapped in
425
- /// right when the open animation begins, which includes the rounded corners.
426
- ///
427
- /// ```dart
428
- /// CupertinoContextMenu(
429
- /// // The FittedBox in the preview here allows the image to animate its
430
- /// // aspect ratio when the CupertinoContextMenu is animating its preview
431
- /// // widget open and closed.
432
- /// previewBuilder: (BuildContext context, Animation<double> animation, Widget child) {
433
- /// return FittedBox(
434
- /// fit: BoxFit.cover,
435
- /// // This ClipRRect rounds the corners of the image when the
436
- /// // CupertinoContextMenu is open, even though it's not rounded when
437
- /// // it's closed. It uses the given animation to animate the corners
438
- /// // in sync with the opening animation.
439
- /// child: ClipRRect(
440
- /// borderRadius: BorderRadius.circular(64.0 * animation.value),
441
- /// child: Image.asset('assets/photo.jpg'),
442
- /// ),
443
- /// );
444
- /// },
445
- /// actions: <Widget>[
446
- /// CupertinoContextMenuAction(
447
- /// child: const Text('Action one'),
448
- /// onPressed: () {},
449
- /// ),
450
- /// ],
451
- /// child: FittedBox(
452
- /// fit: BoxFit.cover,
453
- /// child: Image.asset('assets/photo.jpg'),
454
- /// ),
455
- /// )
456
- /// ```
457
- ///
458
- /// {@end-tool}
459
- @Deprecated (
460
- 'Use CupertinoContextMenu.builder instead. '
461
- 'This feature was deprecated after v3.4.0-34.1.pre.' ,
462
- )
463
- final ContextMenuPreviewBuilder ? previewBuilder;
464
-
465
363
@override
466
364
State <CupertinoContextMenu > createState () => _CupertinoContextMenuState ();
467
365
}
@@ -531,6 +429,19 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker
531
429
return _ContextMenuLocation .left;
532
430
}
533
431
432
+ /// The default preview builder if none is provided. It makes a rectangle
433
+ /// around the child widget with rounded borders, matching the iOS 16 opened
434
+ /// context menu eyeballed on the XCode iOS simulator.
435
+ static Widget _defaultPreviewBuilder (BuildContext context, Animation <double > animation, Widget child) {
436
+ return FittedBox (
437
+ fit: BoxFit .cover,
438
+ child: ClipRRect (
439
+ borderRadius: BorderRadius .circular (_previewBorderRadiusRatio * animation.value),
440
+ child: child,
441
+ ),
442
+ );
443
+ }
444
+
534
445
// Push the new route and open the CupertinoContextMenu overlay.
535
446
void _openContextMenu () {
536
447
setState (() {
@@ -551,7 +462,7 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker
551
462
final Animation <double > localAnimation = Tween <double >(begin: CupertinoContextMenu .animationOpensAt, end: 1 ).animate (animation);
552
463
return widget.builder (context, localAnimation);
553
464
}
554
- return widget. previewBuilder ! (context, animation, widget.child! );
465
+ return _defaultPreviewBuilder (context, animation, widget.child! );
555
466
},
556
467
);
557
468
Navigator .of (context, rootNavigator: true ).push <void >(_route! );
0 commit comments