Skip to content

Commit 2c2fed1

Browse files
Remove deprecated CupertinoContextMenu.previewBuilder (#143990)
It was deprecated in flutter/flutter#110616. Deprecated in flutter/flutter#110616
1 parent 2e4bbb7 commit 2c2fed1

File tree

1 file changed

+22
-111
lines changed

1 file changed

+22
-111
lines changed

packages/flutter/lib/src/cupertino/context_menu.dart

Lines changed: 22 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,6 @@ typedef _DismissCallback = void Function(
5656
double opacity,
5757
);
5858

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-
6859
/// A function that builds the child and handles the transition between the
6960
/// default child and the preview when the CupertinoContextMenu is open.
7061
typedef CupertinoContextMenuBuilder = Widget Function(
@@ -95,23 +86,17 @@ enum _ContextMenuLocation {
9586

9687
/// A full-screen modal route that opens when the [child] is long-pressed.
9788
///
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.
10393
///
10494
/// When closed, the [CupertinoContextMenu] displays the child as if the
10595
/// [CupertinoContextMenu] were not there. Sizing and positioning is unaffected.
10696
/// The menu can be closed like other [PopupRoute]s, such as by tapping the
10797
/// background or by calling `Navigator.pop(context)`. Unlike [PopupRoute], it can
10898
/// also be closed by swiping downwards.
10999
///
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-
///
115100
/// {@tool dartpad}
116101
/// This sample shows a very simple [CupertinoContextMenu] for the Flutter logo.
117102
/// Long press on it to open.
@@ -138,11 +123,6 @@ class CupertinoContextMenu extends StatefulWidget {
138123
required this.actions,
139124
required Widget this.child,
140125
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,
146126
}) : assert(actions.isNotEmpty),
147127
builder = ((BuildContext context, Animation<double> animation) => child);
148128

@@ -158,8 +138,7 @@ class CupertinoContextMenu extends StatefulWidget {
158138
required this.builder,
159139
this.enableHapticFeedback = false,
160140
}) : assert(actions.isNotEmpty),
161-
child = null,
162-
previewBuilder = null;
141+
child = null;
163142

164143
/// Exposes the default border radius for matching iOS 16.0 behavior. This
165144
/// value was eyeballed from the iOS simulator running iOS 16.0.
@@ -353,28 +332,14 @@ class CupertinoContextMenu extends StatefulWidget {
353332
/// {@end-tool}
354333
final CupertinoContextMenuBuilder builder;
355334

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-
369335
// TODO(mitchgoodwin): deprecate [child] with builder refactor https://github.com/flutter/flutter/issues/116306
370336

371337
/// The widget that can be "opened" with the [CupertinoContextMenu].
372338
///
373339
/// 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.
378343
///
379344
/// When the [CupertinoContextMenu] is "closed", this widget acts like a
380345
/// [Container], i.e. it does not constrain its child's size or affect its
@@ -395,73 +360,6 @@ class CupertinoContextMenu extends StatefulWidget {
395360
/// Defaults to false.
396361
final bool enableHapticFeedback;
397362

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-
465363
@override
466364
State<CupertinoContextMenu> createState() => _CupertinoContextMenuState();
467365
}
@@ -531,6 +429,19 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker
531429
return _ContextMenuLocation.left;
532430
}
533431

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+
534445
// Push the new route and open the CupertinoContextMenu overlay.
535446
void _openContextMenu() {
536447
setState(() {
@@ -551,7 +462,7 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker
551462
final Animation<double> localAnimation = Tween<double>(begin: CupertinoContextMenu.animationOpensAt, end: 1).animate(animation);
552463
return widget.builder(context, localAnimation);
553464
}
554-
return widget.previewBuilder!(context, animation, widget.child!);
465+
return _defaultPreviewBuilder(context, animation, widget.child!);
555466
},
556467
);
557468
Navigator.of(context, rootNavigator: true).push<void>(_route!);

0 commit comments

Comments
 (0)