mirror of
https://github.com/flutter/flutter
synced 2024-08-25 11:07:06 +00:00
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
This commit is contained in:
parent
2e4bbb7503
commit
2c2fed1dfb
|
@ -56,15 +56,6 @@ typedef _DismissCallback = void Function(
|
||||||
double opacity,
|
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<double> animation,
|
|
||||||
Widget child,
|
|
||||||
);
|
|
||||||
|
|
||||||
/// A function that builds the child and handles the transition between the
|
/// A function that builds the child and handles the transition between the
|
||||||
/// default child and the preview when the CupertinoContextMenu is open.
|
/// default child and the preview when the CupertinoContextMenu is open.
|
||||||
typedef CupertinoContextMenuBuilder = Widget Function(
|
typedef CupertinoContextMenuBuilder = Widget Function(
|
||||||
|
@ -95,11 +86,10 @@ enum _ContextMenuLocation {
|
||||||
|
|
||||||
/// A full-screen modal route that opens when the [child] is long-pressed.
|
/// A full-screen modal route that opens when the [child] is long-pressed.
|
||||||
///
|
///
|
||||||
/// When open, the [CupertinoContextMenu] shows the child, or the widget returned
|
/// When open, the [CupertinoContextMenu] shows the child in a large full-screen
|
||||||
/// by [previewBuilder] if given, in a large full-screen [Overlay] with a list
|
/// [Overlay] with a list of buttons specified by [actions]. The child/preview is
|
||||||
/// of buttons specified by [actions]. The child/preview is placed in an
|
/// placed in an [Expanded] widget so that it will grow to fill the Overlay if
|
||||||
/// [Expanded] widget so that it will grow to fill the Overlay if its size is
|
/// its size is unconstrained.
|
||||||
/// unconstrained.
|
|
||||||
///
|
///
|
||||||
/// When closed, the [CupertinoContextMenu] displays the child as if the
|
/// When closed, the [CupertinoContextMenu] displays the child as if the
|
||||||
/// [CupertinoContextMenu] were not there. Sizing and positioning is unaffected.
|
/// [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
|
/// background or by calling `Navigator.pop(context)`. Unlike [PopupRoute], it can
|
||||||
/// also be closed by swiping downwards.
|
/// 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}
|
/// {@tool dartpad}
|
||||||
/// This sample shows a very simple [CupertinoContextMenu] for the Flutter logo.
|
/// This sample shows a very simple [CupertinoContextMenu] for the Flutter logo.
|
||||||
/// Long press on it to open.
|
/// Long press on it to open.
|
||||||
|
@ -138,11 +123,6 @@ class CupertinoContextMenu extends StatefulWidget {
|
||||||
required this.actions,
|
required this.actions,
|
||||||
required Widget this.child,
|
required Widget this.child,
|
||||||
this.enableHapticFeedback = false,
|
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),
|
}) : assert(actions.isNotEmpty),
|
||||||
builder = ((BuildContext context, Animation<double> animation) => child);
|
builder = ((BuildContext context, Animation<double> animation) => child);
|
||||||
|
|
||||||
|
@ -158,8 +138,7 @@ class CupertinoContextMenu extends StatefulWidget {
|
||||||
required this.builder,
|
required this.builder,
|
||||||
this.enableHapticFeedback = false,
|
this.enableHapticFeedback = false,
|
||||||
}) : assert(actions.isNotEmpty),
|
}) : assert(actions.isNotEmpty),
|
||||||
child = null,
|
child = null;
|
||||||
previewBuilder = null;
|
|
||||||
|
|
||||||
/// Exposes the default border radius for matching iOS 16.0 behavior. This
|
/// Exposes the default border radius for matching iOS 16.0 behavior. This
|
||||||
/// value was eyeballed from the iOS simulator running iOS 16.0.
|
/// value was eyeballed from the iOS simulator running iOS 16.0.
|
||||||
|
@ -353,28 +332,14 @@ class CupertinoContextMenu extends StatefulWidget {
|
||||||
/// {@end-tool}
|
/// {@end-tool}
|
||||||
final CupertinoContextMenuBuilder builder;
|
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<double> 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
|
// TODO(mitchgoodwin): deprecate [child] with builder refactor https://github.com/flutter/flutter/issues/116306
|
||||||
|
|
||||||
/// The widget that can be "opened" with the [CupertinoContextMenu].
|
/// The widget that can be "opened" with the [CupertinoContextMenu].
|
||||||
///
|
///
|
||||||
/// When the [CupertinoContextMenu] is long-pressed, the menu will open and
|
/// When the [CupertinoContextMenu] is long-pressed, the menu will open and
|
||||||
/// this widget (or the widget returned by [previewBuilder], if provided) will
|
/// this widget will be moved to the new route and placed inside of an
|
||||||
/// be moved to the new route and placed inside of an [Expanded] widget. This
|
/// [Expanded] widget. This allows the child to resize to fit in its place in
|
||||||
/// allows the child to resize to fit in its place in the new route, if it
|
/// the new route, if it doesn't size itself.
|
||||||
/// doesn't size itself.
|
|
||||||
///
|
///
|
||||||
/// When the [CupertinoContextMenu] is "closed", this widget acts like a
|
/// When the [CupertinoContextMenu] is "closed", this widget acts like a
|
||||||
/// [Container], i.e. it does not constrain its child's size or affect its
|
/// [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.
|
/// Defaults to false.
|
||||||
final bool enableHapticFeedback;
|
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<double> 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: <Widget>[
|
|
||||||
/// 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
|
@override
|
||||||
State<CupertinoContextMenu> createState() => _CupertinoContextMenuState();
|
State<CupertinoContextMenu> createState() => _CupertinoContextMenuState();
|
||||||
}
|
}
|
||||||
|
@ -531,6 +429,19 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker
|
||||||
return _ContextMenuLocation.left;
|
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<double> 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.
|
// Push the new route and open the CupertinoContextMenu overlay.
|
||||||
void _openContextMenu() {
|
void _openContextMenu() {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
@ -551,7 +462,7 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker
|
||||||
final Animation<double> localAnimation = Tween<double>(begin: CupertinoContextMenu.animationOpensAt, end: 1).animate(animation);
|
final Animation<double> localAnimation = Tween<double>(begin: CupertinoContextMenu.animationOpensAt, end: 1).animate(animation);
|
||||||
return widget.builder(context, localAnimation);
|
return widget.builder(context, localAnimation);
|
||||||
}
|
}
|
||||||
return widget.previewBuilder!(context, animation, widget.child!);
|
return _defaultPreviewBuilder(context, animation, widget.child!);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
Navigator.of(context, rootNavigator: true).push<void>(_route!);
|
Navigator.of(context, rootNavigator: true).push<void>(_route!);
|
||||||
|
|
Loading…
Reference in a new issue