From 0bde95dc068fc155b18b7332e696b7c1b1ba5e2e Mon Sep 17 00:00:00 2001 From: Chinmoy Date: Sat, 11 Nov 2023 04:17:22 +0530 Subject: [PATCH] Deprecates onWillAccept and onAccept callbacks in DragTarget. (#133691) This PR deprecates `onWillAccept` and `onAccept` over `onWillAcceptWithDetails` and `onAcceptWithDetails`. Fixes: #133347 --- dev/manual_tests/lib/drag_and_drop.dart | 8 ++-- .../lib/widgets/drag_target/draggable.0.dart | 4 +- .../fix_data/fix_widgets/fix_drag_target.yaml | 46 +++++++++++++++++++ .../flutter/lib/src/widgets/drag_target.dart | 20 ++++++++ .../test_fixes/cupertino/drag_target.dart | 17 +++++++ .../cupertino/drag_target.dart.expect | 17 +++++++ .../test_fixes/material/drag_target.dart | 17 +++++++ .../material/drag_target.dart.expect | 17 +++++++ .../test_fixes/widgets/drag_target.dart | 17 +++++++ .../widgets/drag_target.dart.expect | 17 +++++++ 10 files changed, 174 insertions(+), 6 deletions(-) create mode 100644 packages/flutter/lib/fix_data/fix_widgets/fix_drag_target.yaml create mode 100644 packages/flutter/test_fixes/cupertino/drag_target.dart create mode 100644 packages/flutter/test_fixes/cupertino/drag_target.dart.expect create mode 100644 packages/flutter/test_fixes/material/drag_target.dart create mode 100644 packages/flutter/test_fixes/material/drag_target.dart.expect create mode 100644 packages/flutter/test_fixes/widgets/drag_target.dart create mode 100644 packages/flutter/test_fixes/widgets/drag_target.dart.expect diff --git a/dev/manual_tests/lib/drag_and_drop.dart b/dev/manual_tests/lib/drag_and_drop.dart index db0080aa0a0..bcdbcd49690 100644 --- a/dev/manual_tests/lib/drag_and_drop.dart +++ b/dev/manual_tests/lib/drag_and_drop.dart @@ -16,16 +16,16 @@ class ExampleDragTarget extends StatefulWidget { class ExampleDragTargetState extends State { Color _color = Colors.grey; - void _handleAccept(Color data) { + void _handleAccept(DragTargetDetails details) { setState(() { - _color = data; + _color = details.data; }); } @override Widget build(BuildContext context) { return DragTarget( - onAccept: _handleAccept, + onAcceptWithDetails: _handleAccept, builder: (BuildContext context, List data, List rejectedData) { return Container( height: 100.0, @@ -217,7 +217,7 @@ class MovableBall extends StatelessWidget { ); } else { return DragTarget( - onAccept: (bool data) { callback(position); }, + onAcceptWithDetails: (DragTargetDetails data) { callback(position); }, builder: (BuildContext context, List accepted, List rejected) { return dashedBall; }, diff --git a/examples/api/lib/widgets/drag_target/draggable.0.dart b/examples/api/lib/widgets/drag_target/draggable.0.dart index 2d8914a2c06..79192cc9176 100644 --- a/examples/api/lib/widgets/drag_target/draggable.0.dart +++ b/examples/api/lib/widgets/drag_target/draggable.0.dart @@ -78,9 +78,9 @@ class _DraggableExampleState extends State { ), ); }, - onAccept: (int data) { + onAcceptWithDetails: (DragTargetDetails details) { setState(() { - acceptedData += data; + acceptedData += details.data; }); }, ), diff --git a/packages/flutter/lib/fix_data/fix_widgets/fix_drag_target.yaml b/packages/flutter/lib/fix_data/fix_widgets/fix_drag_target.yaml new file mode 100644 index 00000000000..ab10142a8b8 --- /dev/null +++ b/packages/flutter/lib/fix_data/fix_widgets/fix_drag_target.yaml @@ -0,0 +1,46 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for DragTarget from the Widgets library. * +version: 1 +transforms: + + # Changes made in https://github.com/flutter/flutter/pull/133691 + - title: "Migrate 'onWillAccept' to 'onWillAcceptWithDetails'" + date: 2023-08-30 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'DragTarget' + changes: + - kind: 'renameParameter' + oldName: 'onWillAccept' + newName: 'onWillAcceptWithDetails' + + # Changes made in https://github.com/flutter/flutter/pull/133691 + - title: "Migrate 'onAccept' to 'onAcceptWithDetails'" + date: 2023-08-30 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'DragTarget' + changes: + - kind: 'renameParameter' + oldName: 'onAccept' + newName: 'onAcceptWithDetails' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/packages/flutter/lib/src/widgets/drag_target.dart b/packages/flutter/lib/src/widgets/drag_target.dart index b6567fd01e5..c68b8665c97 100644 --- a/packages/flutter/lib/src/widgets/drag_target.dart +++ b/packages/flutter/lib/src/widgets/drag_target.dart @@ -611,8 +611,18 @@ class DragTarget extends StatefulWidget { const DragTarget({ super.key, required this.builder, + @Deprecated( + 'Use onWillAcceptWithDetails instead. ' + 'This callback is similar to onWillAcceptWithDetails but does not provide drag details. ' + 'This feature was deprecated after v3.14.0-0.2.pre.' + ) this.onWillAccept, this.onWillAcceptWithDetails, + @Deprecated( + 'Use onAcceptWithDetails instead. ' + 'This callback is similar to onAcceptWithDetails but does not provide drag details. ' + 'This feature was deprecated after v3.14.0-0.2.pre.' + ) this.onAccept, this.onAcceptWithDetails, this.onLeave, @@ -636,6 +646,11 @@ class DragTarget extends StatefulWidget { /// Equivalent to [onWillAcceptWithDetails], but only includes the data. /// /// Must not be provided if [onWillAcceptWithDetails] is provided. + @Deprecated( + 'Use onWillAcceptWithDetails instead. ' + 'This callback is similar to onWillAcceptWithDetails but does not provide drag details. ' + 'This feature was deprecated after v3.14.0-0.2.pre.' + ) final DragTargetWillAccept? onWillAccept; /// Called to determine whether this widget is interested in receiving a given @@ -655,6 +670,11 @@ class DragTarget extends StatefulWidget { /// It will not be called if `data` is `null`. /// /// Equivalent to [onAcceptWithDetails], but only includes the data. + @Deprecated( + 'Use onAcceptWithDetails instead. ' + 'This callback is similar to onAcceptWithDetails but does not provide drag details. ' + 'This feature was deprecated after v3.14.0-0.2.pre.' + ) final DragTargetAccept? onAccept; /// Called when an acceptable piece of data was dropped over this drag target. diff --git a/packages/flutter/test_fixes/cupertino/drag_target.dart b/packages/flutter/test_fixes/cupertino/drag_target.dart new file mode 100644 index 00000000000..5aa9b614992 --- /dev/null +++ b/packages/flutter/test_fixes/cupertino/drag_target.dart @@ -0,0 +1,17 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/cupertino.dart'; + +void main() { + // Changes made in https://github.com/flutter/flutter/pull/133691 + const dragTarget = DragTarget(); + dragTarget = DragTarget(onWillAccept: (data) => ()); + dragTarget = DragTarget(onWillAcceptWithDetails: (data) => ()); + + // Changes made in https://github.com/flutter/flutter/pull/133691 + const dragTarget = DragTarget(); + dragTarget = DragTarget(onAccept: (data) => ()); + dragTarget = DragTarget(onAcceptWithDetails: (data) => ()); +} diff --git a/packages/flutter/test_fixes/cupertino/drag_target.dart.expect b/packages/flutter/test_fixes/cupertino/drag_target.dart.expect new file mode 100644 index 00000000000..0c8207e3bd5 --- /dev/null +++ b/packages/flutter/test_fixes/cupertino/drag_target.dart.expect @@ -0,0 +1,17 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/cupertino.dart'; + +void main() { + // Changes made in https://github.com/flutter/flutter/pull/133691 + const dragTarget = DragTarget(); + dragTarget = DragTarget(onWillAcceptWithDetails: (data) => ()); + dragTarget = DragTarget(onWillAcceptWithDetails: (data) => ()); + + // Changes made in https://github.com/flutter/flutter/pull/133691 + const dragTarget = DragTarget(); + dragTarget = DragTarget(onAcceptWithDetails: (data) => ()); + dragTarget = DragTarget(onAcceptWithDetails: (data) => ()); +} diff --git a/packages/flutter/test_fixes/material/drag_target.dart b/packages/flutter/test_fixes/material/drag_target.dart new file mode 100644 index 00000000000..377cacabee0 --- /dev/null +++ b/packages/flutter/test_fixes/material/drag_target.dart @@ -0,0 +1,17 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; + +void main() { + // Changes made in https://github.com/flutter/flutter/pull/133691 + const dragTarget = DragTarget(); + dragTarget = DragTarget(onWillAccept: (data) => ()); + dragTarget = DragTarget(onWillAcceptWithDetails: (data) => ()); + + // Changes made in https://github.com/flutter/flutter/pull/133691 + const dragTarget = DragTarget(); + dragTarget = DragTarget(onAccept: (data) => ()); + dragTarget = DragTarget(onAcceptWithDetails: (data) => ()); +} diff --git a/packages/flutter/test_fixes/material/drag_target.dart.expect b/packages/flutter/test_fixes/material/drag_target.dart.expect new file mode 100644 index 00000000000..050408df304 --- /dev/null +++ b/packages/flutter/test_fixes/material/drag_target.dart.expect @@ -0,0 +1,17 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; + +void main() { + // Changes made in https://github.com/flutter/flutter/pull/133691 + const dragTarget = DragTarget(); + dragTarget = DragTarget(onWillAcceptWithDetails: (data) => ()); + dragTarget = DragTarget(onWillAcceptWithDetails: (data) => ()); + + // Changes made in https://github.com/flutter/flutter/pull/133691 + const dragTarget = DragTarget(); + dragTarget = DragTarget(onAcceptWithDetails: (data) => ()); + dragTarget = DragTarget(onAcceptWithDetails: (data) => ()); +} diff --git a/packages/flutter/test_fixes/widgets/drag_target.dart b/packages/flutter/test_fixes/widgets/drag_target.dart new file mode 100644 index 00000000000..d7b2e1ee119 --- /dev/null +++ b/packages/flutter/test_fixes/widgets/drag_target.dart @@ -0,0 +1,17 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +void main() { + // Changes made in https://github.com/flutter/flutter/pull/133691 + const dragTarget = DragTarget(); + dragTarget = DragTarget(onWillAccept: (data) => ()); + dragTarget = DragTarget(onWillAcceptWithDetails: (data) => ()); + + // Changes made in https://github.com/flutter/flutter/pull/133691 + const dragTarget = DragTarget(); + dragTarget = DragTarget(onAccept: (data) => ()); + dragTarget = DragTarget(onAcceptWithDetails: (data) => ()); +} diff --git a/packages/flutter/test_fixes/widgets/drag_target.dart.expect b/packages/flutter/test_fixes/widgets/drag_target.dart.expect new file mode 100644 index 00000000000..e71240e1088 --- /dev/null +++ b/packages/flutter/test_fixes/widgets/drag_target.dart.expect @@ -0,0 +1,17 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +void main() { + // Changes made in https://github.com/flutter/flutter/pull/133691 + const dragTarget = DragTarget(); + dragTarget = DragTarget(onWillAcceptWithDetails: (data) => ()); + dragTarget = DragTarget(onWillAcceptWithDetails: (data) => ()); + + // Changes made in https://github.com/flutter/flutter/pull/133691 + const dragTarget = DragTarget(); + dragTarget = DragTarget(onAcceptWithDetails: (data) => ()); + dragTarget = DragTarget(onAcceptWithDetails: (data) => ()); +}