public void didDrop(_DragAvatar <T> avatar) { D.assert(this._candidateAvatars.Contains(avatar)); if (!this.mounted) { return; } this.setState(() => { this._candidateAvatars.Remove(avatar); }); if (this.widget.onAccept != null) { this.widget.onAccept(avatar.data); } }
public bool didEnter(_DragAvatar <T> avatar) { D.assert(!this._candidateAvatars.Contains(avatar)); D.assert(!this._rejectedAvatars.Contains(avatar)); if (avatar.data is T && (this.widget.onWillAccept == null || this.widget.onWillAccept(avatar.data))) { this.setState(() => { this._candidateAvatars.Add(avatar); }); return(true); } this._rejectedAvatars.Add(avatar); return(false); }
public void didLeave(_DragAvatar <T> avatar) { D.assert(this._candidateAvatars.Contains(avatar) || this._rejectedAvatars.Contains(avatar)); if (!this.mounted) { return; } this.setState(() => { this._candidateAvatars.Remove(avatar); this._rejectedAvatars.Remove(avatar); }); if (this.widget.onLeave != null) { this.widget.onLeave(avatar.data); } }
public void didLeave(_DragAvatar <T> avatar) { D.assert(_candidateAvatars.Contains(avatar) || _rejectedAvatars.Contains(avatar)); if (!mounted) { return; } setState(() => { _candidateAvatars.Remove(avatar); _rejectedAvatars.Remove(avatar); }); if (widget.onLeave != null) { widget.onLeave(avatar.data); } }
public bool didEnter(_DragAvatar <T> avatar) { D.assert(!_candidateAvatars.Contains(avatar)); D.assert(!_rejectedAvatars.Contains(avatar)); if (avatar is _DragAvatar <T> && (widget.onWillAccept == null || widget.onWillAccept(avatar.data))) { setState(() => { _candidateAvatars.Add(avatar); }); return(true); } else { setState(() => { _rejectedAvatars.Add(avatar); }); return(false); } }
_DragAvatar <T> _startDrag(Offset position) { if (this.widget.maxSimultaneousDrags != null && this._activeCount >= this.widget.maxSimultaneousDrags) { return(null); } var dragStartPoint = Offset.zero; switch (this.widget.dragAnchor) { case DragAnchor.child: RenderBox renderObject = this.context.findRenderObject() as RenderBox; dragStartPoint = renderObject.globalToLocal(position); break; case DragAnchor.pointer: dragStartPoint = Offset.zero; break; } this.setState(() => { this._activeCount += 1; }); _DragAvatar <T> avatar = new _DragAvatar <T>( overlayState: Overlay.of(this.context, debugRequiredFor: this.widget), data: this.widget.data, axis: this.widget.axis, initialPosition: position, dragStartPoint: dragStartPoint, feedback: this.widget.feedback, feedbackOffset: this.widget.feedbackOffset, onDragEnd: (Velocity velocity, Offset offset, bool wasAccepted) => { if (this.mounted) { this.setState(() => { this._activeCount -= 1; }); } else { this._activeCount -= 1; this._disposeRecognizerIfInactive(); } if (this.mounted && this.widget.onDragEnd != null) { this.widget.onDragEnd(new DraggableDetails( wasAccepted: wasAccepted, velocity: velocity, offset: offset )); } if (wasAccepted && this.widget.onDragCompleted != null) { this.widget.onDragCompleted(); } if (!wasAccepted && this.widget.onDraggableCanceled != null) { this.widget.onDraggableCanceled(velocity, offset); } } ); if (this.widget.onDragStarted != null) { this.widget.onDragStarted(); } return(avatar); }