mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 08:46:18 +01:00
Make draggable widget more generic
This commit is contained in:
parent
0e6fe1dede
commit
791a65713b
3 changed files with 12 additions and 20 deletions
|
@ -15,12 +15,11 @@ class Draggable<T extends Object> 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<T extends Object> extends StatelessWidget {
|
|||
}
|
||||
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
fit: StackFit.passthrough,
|
||||
children: [
|
||||
LongPressDraggable<T>(
|
||||
data: data,
|
||||
|
@ -48,11 +47,10 @@ class Draggable<T extends Object> 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<T extends Object> 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;
|
||||
}
|
||||
|
|
|
@ -63,7 +63,11 @@ class _DraggableItemListState<T extends DraggableItemMetadata>
|
|||
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<T extends DraggableItemMetadata>
|
|||
onDragEndedAny: () {
|
||||
widget.onDraggingChanged?.call(false);
|
||||
},
|
||||
feedbackSize: Size(widget.maxCrossAxisExtent * .65,
|
||||
widget.maxCrossAxisExtent * .65),
|
||||
child: widget.itemBuilder(context, i, meta),
|
||||
);
|
||||
} else {
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue