From 791a65713b5a89f27f9487d0a41a3efdf2ce6c0e Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Sat, 26 Oct 2024 19:41:03 +0800 Subject: [PATCH] Make draggable widget more generic --- app/lib/widget/draggable.dart | 21 +++++++------------ app/lib/widget/draggable_item_list.dart | 8 ++++--- .../widget/settings/viewer_app_bar/view.dart | 3 --- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/app/lib/widget/draggable.dart b/app/lib/widget/draggable.dart index 75cfd0d8..b36195d8 100644 --- a/app/lib/widget/draggable.dart +++ b/app/lib/widget/draggable.dart @@ -15,12 +15,11 @@ class Draggable extends StatelessWidget { this.onDropAfter, this.onDragStarted, this.onDragEndedAny, - this.feedbackSize, }); @override - build(BuildContext context) { - buildIndicator(alignment, isActive) { + Widget build(BuildContext context) { + Widget buildIndicator(alignment, isActive) { return Stack( children: [ Container(), @@ -39,7 +38,7 @@ class Draggable extends StatelessWidget { } return Stack( - fit: StackFit.expand, + fit: StackFit.passthrough, children: [ LongPressDraggable( data: data, @@ -48,11 +47,10 @@ class Draggable extends StatelessWidget { onDragEnd: (_) => onDragEndedAny?.call(), onDragCompleted: onDragEndedAny, onDraggableCanceled: (v, o) => onDragEndedAny?.call(), - feedback: FractionalTranslation( - translation: const Offset(-.5, -.5), - child: SizedBox( - width: feedbackSize?.width ?? 128, - height: feedbackSize?.height ?? 128, + feedback: Material( + type: MaterialType.transparency, + child: FractionalTranslation( + translation: const Offset(-.5, -.5), child: Opacity( opacity: .5, child: feedback ?? child, @@ -122,9 +120,4 @@ class Draggable extends StatelessWidget { /// /// The callback might be called multiple times per each drag event final VoidCallback? onDragEndedAny; - - /// Size of the feedback widget that appears under the pointer. - /// - /// Right now a translucent version of [child] is being shown - final Size? feedbackSize; } diff --git a/app/lib/widget/draggable_item_list.dart b/app/lib/widget/draggable_item_list.dart index 5d70fe3f..2f604ad7 100644 --- a/app/lib/widget/draggable_item_list.dart +++ b/app/lib/widget/draggable_item_list.dart @@ -63,7 +63,11 @@ class _DraggableItemListState if (meta.isDraggable) { return my.Draggable<_DraggableData>( data: _DraggableData(i, meta), - feedback: widget.itemDragFeedbackBuilder?.call(context, i, meta), + feedback: SizedBox( + width: widget.maxCrossAxisExtent * .65, + height: widget.maxCrossAxisExtent * .65, + child: widget.itemDragFeedbackBuilder?.call(context, i, meta), + ), onDropBefore: (data) => _onMoved(data.index, i, true), onDropAfter: (data) => _onMoved(data.index, i, false), onDragStarted: () { @@ -72,8 +76,6 @@ class _DraggableItemListState onDragEndedAny: () { widget.onDraggingChanged?.call(false); }, - feedbackSize: Size(widget.maxCrossAxisExtent * .65, - widget.maxCrossAxisExtent * .65), child: widget.itemBuilder(context, i, meta), ); } else { diff --git a/app/lib/widget/settings/viewer_app_bar/view.dart b/app/lib/widget/settings/viewer_app_bar/view.dart index b2a21581..4a704b54 100644 --- a/app/lib/widget/settings/viewer_app_bar/view.dart +++ b/app/lib/widget/settings/viewer_app_bar/view.dart @@ -26,7 +26,6 @@ class _DemoView extends StatelessWidget { feedback: _DraggingButton( child: _DemoButtonDelegate(e), ), - feedbackSize: const Size.square(48), onDropBefore: (data) { context.addEvent(_MoveButton.before( which: data, @@ -148,7 +147,6 @@ class _DemoBottomView extends StatelessWidget { feedback: _DraggingButton( child: _DemoButtonDelegate(e), ), - feedbackSize: const Size.square(48), onDropBefore: (data) { context.addEvent(_MoveButton.before( which: data, @@ -232,7 +230,6 @@ class _CandidateGrid extends StatelessWidget { feedback: _DraggingButton( child: _DemoButtonDelegate(e), ), - feedbackSize: const Size.square(48), child: _CandidateButtonDelegate(e), )) .toList(),