mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-13 18:58:53 +01:00
Support using diff widget for drag feedback
This commit is contained in:
parent
da878c39fe
commit
62e72bdf81
2 changed files with 9 additions and 1 deletions
|
@ -7,6 +7,7 @@ class Draggable<T> extends StatelessWidget {
|
|||
Key key,
|
||||
@required this.data,
|
||||
@required this.child,
|
||||
this.feedback,
|
||||
this.onDropBefore,
|
||||
this.onDropAfter,
|
||||
this.onDragStarted,
|
||||
|
@ -53,7 +54,7 @@ class Draggable<T> extends StatelessWidget {
|
|||
height: feedbackSize?.height ?? 128,
|
||||
child: Opacity(
|
||||
opacity: .5,
|
||||
child: child,
|
||||
child: feedback ?? child,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -104,6 +105,7 @@ class Draggable<T> extends StatelessWidget {
|
|||
|
||||
final T data;
|
||||
final Widget child;
|
||||
final Widget feedback;
|
||||
|
||||
/// Called when some item dropped before this item
|
||||
final DragTargetAccept<T> onDropBefore;
|
||||
|
|
|
@ -6,6 +6,11 @@ import 'package:nc_photos/widget/measurable_item_list.dart';
|
|||
abstract class DraggableItem {
|
||||
Widget buildWidget(BuildContext context);
|
||||
|
||||
/// The widget to show under the pointer when a drag is under way.
|
||||
///
|
||||
/// Return null if you wish to just use the same widget as display
|
||||
Widget buildDragFeedbackWidget(BuildContext context) => null;
|
||||
|
||||
bool get isDraggable => false;
|
||||
DragTargetAccept<DraggableItem> get onDropBefore => null;
|
||||
DragTargetAccept<DraggableItem> get onDropAfter => null;
|
||||
|
@ -40,6 +45,7 @@ mixin DraggableItemListMixin<T extends StatefulWidget> on State<T> {
|
|||
return _.Draggable(
|
||||
data: item,
|
||||
child: item.buildWidget(context),
|
||||
feedback: item.buildDragFeedbackWidget(context),
|
||||
onDropBefore: item.onDropBefore,
|
||||
onDropAfter: item.onDropAfter,
|
||||
onDragStarted: item.onDragStarted,
|
||||
|
|
Loading…
Reference in a new issue