mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +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.onDropAfter,
|
||||||
this.onDragStarted,
|
this.onDragStarted,
|
||||||
this.onDragEndedAny,
|
this.onDragEndedAny,
|
||||||
this.feedbackSize,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
buildIndicator(alignment, isActive) {
|
Widget buildIndicator(alignment, isActive) {
|
||||||
return Stack(
|
return Stack(
|
||||||
children: [
|
children: [
|
||||||
Container(),
|
Container(),
|
||||||
|
@ -39,7 +38,7 @@ class Draggable<T extends Object> extends StatelessWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
return Stack(
|
return Stack(
|
||||||
fit: StackFit.expand,
|
fit: StackFit.passthrough,
|
||||||
children: [
|
children: [
|
||||||
LongPressDraggable<T>(
|
LongPressDraggable<T>(
|
||||||
data: data,
|
data: data,
|
||||||
|
@ -48,11 +47,10 @@ class Draggable<T extends Object> extends StatelessWidget {
|
||||||
onDragEnd: (_) => onDragEndedAny?.call(),
|
onDragEnd: (_) => onDragEndedAny?.call(),
|
||||||
onDragCompleted: onDragEndedAny,
|
onDragCompleted: onDragEndedAny,
|
||||||
onDraggableCanceled: (v, o) => onDragEndedAny?.call(),
|
onDraggableCanceled: (v, o) => onDragEndedAny?.call(),
|
||||||
feedback: FractionalTranslation(
|
feedback: Material(
|
||||||
translation: const Offset(-.5, -.5),
|
type: MaterialType.transparency,
|
||||||
child: SizedBox(
|
child: FractionalTranslation(
|
||||||
width: feedbackSize?.width ?? 128,
|
translation: const Offset(-.5, -.5),
|
||||||
height: feedbackSize?.height ?? 128,
|
|
||||||
child: Opacity(
|
child: Opacity(
|
||||||
opacity: .5,
|
opacity: .5,
|
||||||
child: feedback ?? child,
|
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
|
/// The callback might be called multiple times per each drag event
|
||||||
final VoidCallback? onDragEndedAny;
|
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) {
|
if (meta.isDraggable) {
|
||||||
return my.Draggable<_DraggableData>(
|
return my.Draggable<_DraggableData>(
|
||||||
data: _DraggableData(i, meta),
|
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),
|
onDropBefore: (data) => _onMoved(data.index, i, true),
|
||||||
onDropAfter: (data) => _onMoved(data.index, i, false),
|
onDropAfter: (data) => _onMoved(data.index, i, false),
|
||||||
onDragStarted: () {
|
onDragStarted: () {
|
||||||
|
@ -72,8 +76,6 @@ class _DraggableItemListState<T extends DraggableItemMetadata>
|
||||||
onDragEndedAny: () {
|
onDragEndedAny: () {
|
||||||
widget.onDraggingChanged?.call(false);
|
widget.onDraggingChanged?.call(false);
|
||||||
},
|
},
|
||||||
feedbackSize: Size(widget.maxCrossAxisExtent * .65,
|
|
||||||
widget.maxCrossAxisExtent * .65),
|
|
||||||
child: widget.itemBuilder(context, i, meta),
|
child: widget.itemBuilder(context, i, meta),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -26,7 +26,6 @@ class _DemoView extends StatelessWidget {
|
||||||
feedback: _DraggingButton(
|
feedback: _DraggingButton(
|
||||||
child: _DemoButtonDelegate(e),
|
child: _DemoButtonDelegate(e),
|
||||||
),
|
),
|
||||||
feedbackSize: const Size.square(48),
|
|
||||||
onDropBefore: (data) {
|
onDropBefore: (data) {
|
||||||
context.addEvent(_MoveButton.before(
|
context.addEvent(_MoveButton.before(
|
||||||
which: data,
|
which: data,
|
||||||
|
@ -148,7 +147,6 @@ class _DemoBottomView extends StatelessWidget {
|
||||||
feedback: _DraggingButton(
|
feedback: _DraggingButton(
|
||||||
child: _DemoButtonDelegate(e),
|
child: _DemoButtonDelegate(e),
|
||||||
),
|
),
|
||||||
feedbackSize: const Size.square(48),
|
|
||||||
onDropBefore: (data) {
|
onDropBefore: (data) {
|
||||||
context.addEvent(_MoveButton.before(
|
context.addEvent(_MoveButton.before(
|
||||||
which: data,
|
which: data,
|
||||||
|
@ -232,7 +230,6 @@ class _CandidateGrid extends StatelessWidget {
|
||||||
feedback: _DraggingButton(
|
feedback: _DraggingButton(
|
||||||
child: _DemoButtonDelegate(e),
|
child: _DemoButtonDelegate(e),
|
||||||
),
|
),
|
||||||
feedbackSize: const Size.square(48),
|
|
||||||
child: _CandidateButtonDelegate(e),
|
child: _CandidateButtonDelegate(e),
|
||||||
))
|
))
|
||||||
.toList(),
|
.toList(),
|
||||||
|
|
Loading…
Reference in a new issue