From 2c2fed1dfb5c96cb7e930908f907a27f7ebcb70d Mon Sep 17 00:00:00 2001 From: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Date: Tue, 27 Feb 2024 14:49:10 -0800 Subject: [PATCH] Remove deprecated `CupertinoContextMenu.previewBuilder` (#143990) It was deprecated in https://github.com/flutter/flutter/pull/110616. Deprecated in https://github.com/flutter/flutter/pull/110616 --- .../lib/src/cupertino/context_menu.dart | 133 +++--------------- 1 file changed, 22 insertions(+), 111 deletions(-) diff --git a/packages/flutter/lib/src/cupertino/context_menu.dart b/packages/flutter/lib/src/cupertino/context_menu.dart index e602eaf1d7e..1240803909c 100644 --- a/packages/flutter/lib/src/cupertino/context_menu.dart +++ b/packages/flutter/lib/src/cupertino/context_menu.dart @@ -56,15 +56,6 @@ typedef _DismissCallback = void Function( double opacity, ); -/// A function that produces the preview when the CupertinoContextMenu is open. -/// -/// Called every time the animation value changes. -typedef ContextMenuPreviewBuilder = Widget Function( - BuildContext context, - Animation animation, - Widget child, -); - /// A function that builds the child and handles the transition between the /// default child and the preview when the CupertinoContextMenu is open. typedef CupertinoContextMenuBuilder = Widget Function( @@ -95,11 +86,10 @@ enum _ContextMenuLocation { /// A full-screen modal route that opens when the [child] is long-pressed. /// -/// When open, the [CupertinoContextMenu] shows the child, or the widget returned -/// by [previewBuilder] if given, in a large full-screen [Overlay] with a list -/// of buttons specified by [actions]. The child/preview is placed in an -/// [Expanded] widget so that it will grow to fill the Overlay if its size is -/// unconstrained. +/// When open, the [CupertinoContextMenu] shows the child in a large full-screen +/// [Overlay] with a list of buttons specified by [actions]. The child/preview is +/// placed in an [Expanded] widget so that it will grow to fill the Overlay if +/// its size is unconstrained. /// /// When closed, the [CupertinoContextMenu] displays the child as if the /// [CupertinoContextMenu] were not there. Sizing and positioning is unaffected. @@ -107,11 +97,6 @@ enum _ContextMenuLocation { /// background or by calling `Navigator.pop(context)`. Unlike [PopupRoute], it can /// also be closed by swiping downwards. /// -/// The [previewBuilder] parameter is most commonly used to display a slight -/// variation of [child]. See [previewBuilder] for an example of rounding the -/// child's corners and allowing its aspect ratio to expand, similar to the -/// Photos app on iOS. -/// /// {@tool dartpad} /// This sample shows a very simple [CupertinoContextMenu] for the Flutter logo. /// Long press on it to open. @@ -138,11 +123,6 @@ class CupertinoContextMenu extends StatefulWidget { required this.actions, required Widget this.child, this.enableHapticFeedback = false, - @Deprecated( - 'Use CupertinoContextMenu.builder instead. ' - 'This feature was deprecated after v3.4.0-34.1.pre.', - ) - this.previewBuilder = _defaultPreviewBuilder, }) : assert(actions.isNotEmpty), builder = ((BuildContext context, Animation animation) => child); @@ -158,8 +138,7 @@ class CupertinoContextMenu extends StatefulWidget { required this.builder, this.enableHapticFeedback = false, }) : assert(actions.isNotEmpty), - child = null, - previewBuilder = null; + child = null; /// Exposes the default border radius for matching iOS 16.0 behavior. This /// value was eyeballed from the iOS simulator running iOS 16.0. @@ -353,28 +332,14 @@ class CupertinoContextMenu extends StatefulWidget { /// {@end-tool} final CupertinoContextMenuBuilder builder; - /// The default preview builder if none is provided. It makes a rectangle - /// around the child widget with rounded borders, matching the iOS 16 opened - /// context menu eyeballed on the XCode iOS simulator. - static Widget _defaultPreviewBuilder(BuildContext context, Animation animation, Widget child) { - return FittedBox( - fit: BoxFit.cover, - child: ClipRRect( - borderRadius: BorderRadius.circular(_previewBorderRadiusRatio * animation.value), - child: child, - ), - ); - } - // TODO(mitchgoodwin): deprecate [child] with builder refactor https://github.com/flutter/flutter/issues/116306 /// The widget that can be "opened" with the [CupertinoContextMenu]. /// /// When the [CupertinoContextMenu] is long-pressed, the menu will open and - /// this widget (or the widget returned by [previewBuilder], if provided) will - /// be moved to the new route and placed inside of an [Expanded] widget. This - /// allows the child to resize to fit in its place in the new route, if it - /// doesn't size itself. + /// this widget will be moved to the new route and placed inside of an + /// [Expanded] widget. This allows the child to resize to fit in its place in + /// the new route, if it doesn't size itself. /// /// When the [CupertinoContextMenu] is "closed", this widget acts like a /// [Container], i.e. it does not constrain its child's size or affect its @@ -395,73 +360,6 @@ class CupertinoContextMenu extends StatefulWidget { /// Defaults to false. final bool enableHapticFeedback; - /// A function that returns an alternative widget to show when the - /// [CupertinoContextMenu] is open. - /// - /// If not specified, [child] will be shown. - /// - /// The preview is often used to show a slight variation of the [child]. For - /// example, the child could be given rounded corners in the preview but have - /// sharp corners when in the page. - /// - /// In addition to the current [BuildContext], the function is also called - /// with an [Animation] and the [child]. The animation goes from 0 to 1 when - /// the CupertinoContextMenu opens, and from 1 to 0 when it closes, and it can - /// be used to animate the preview in sync with this opening and closing. The - /// child parameter provides access to the child displayed when the - /// CupertinoContextMenu is closed. - /// - /// {@tool snippet} - /// - /// Below is an example of using [previewBuilder] to show an image tile that's - /// similar to each tile in the iOS iPhoto app's context menu. Several of - /// these could be used in a GridView for a similar effect. - /// - /// When opened, the child animates to show its full aspect ratio and has - /// rounded corners. The larger size of the open CupertinoContextMenu allows - /// the FittedBox to fit the entire image, even when it has a very tall or - /// wide aspect ratio compared to the square of a GridView, so this animates - /// into view as the CupertinoContextMenu is opened. The preview is swapped in - /// right when the open animation begins, which includes the rounded corners. - /// - /// ```dart - /// CupertinoContextMenu( - /// // The FittedBox in the preview here allows the image to animate its - /// // aspect ratio when the CupertinoContextMenu is animating its preview - /// // widget open and closed. - /// previewBuilder: (BuildContext context, Animation animation, Widget child) { - /// return FittedBox( - /// fit: BoxFit.cover, - /// // This ClipRRect rounds the corners of the image when the - /// // CupertinoContextMenu is open, even though it's not rounded when - /// // it's closed. It uses the given animation to animate the corners - /// // in sync with the opening animation. - /// child: ClipRRect( - /// borderRadius: BorderRadius.circular(64.0 * animation.value), - /// child: Image.asset('assets/photo.jpg'), - /// ), - /// ); - /// }, - /// actions: [ - /// CupertinoContextMenuAction( - /// child: const Text('Action one'), - /// onPressed: () {}, - /// ), - /// ], - /// child: FittedBox( - /// fit: BoxFit.cover, - /// child: Image.asset('assets/photo.jpg'), - /// ), - /// ) - /// ``` - /// - /// {@end-tool} - @Deprecated( - 'Use CupertinoContextMenu.builder instead. ' - 'This feature was deprecated after v3.4.0-34.1.pre.', - ) - final ContextMenuPreviewBuilder? previewBuilder; - @override State createState() => _CupertinoContextMenuState(); } @@ -531,6 +429,19 @@ class _CupertinoContextMenuState extends State with Ticker return _ContextMenuLocation.left; } + /// The default preview builder if none is provided. It makes a rectangle + /// around the child widget with rounded borders, matching the iOS 16 opened + /// context menu eyeballed on the XCode iOS simulator. + static Widget _defaultPreviewBuilder(BuildContext context, Animation animation, Widget child) { + return FittedBox( + fit: BoxFit.cover, + child: ClipRRect( + borderRadius: BorderRadius.circular(_previewBorderRadiusRatio * animation.value), + child: child, + ), + ); + } + // Push the new route and open the CupertinoContextMenu overlay. void _openContextMenu() { setState(() { @@ -551,7 +462,7 @@ class _CupertinoContextMenuState extends State with Ticker final Animation localAnimation = Tween(begin: CupertinoContextMenu.animationOpensAt, end: 1).animate(animation); return widget.builder(context, localAnimation); } - return widget.previewBuilder!(context, animation, widget.child!); + return _defaultPreviewBuilder(context, animation, widget.child!); }, ); Navigator.of(context, rootNavigator: true).push(_route!);