Skip to main content

Draggable

Struct Draggable 

Source
pub struct Draggable<T: 'static> {
Show 20 fields pub key: Option<KeyRef>, pub data: Option<Rc<T>>, pub axis: Option<Axis>, pub child: WidgetRef, pub child_when_dragging: Option<WidgetRef>, pub feedback: WidgetRef, pub feedback_offset: Offset, pub drag_anchor_strategy: DragAnchorStrategy<T>, pub ignoring_feedback_semantics: bool, pub ignoring_feedback_pointer: bool, pub affinity: Option<Axis>, pub max_simultaneous_drags: Option<usize>, pub on_drag_started: Option<Listener>, pub on_drag_update: Option<DragUpdateCallback>, pub on_draggable_canceled: Option<DraggableCanceledCallback>, pub on_drag_completed: Option<Listener>, pub on_drag_end: Option<DragEndCallback>, pub root_overlay: bool, pub hit_test_behavior: HitTestBehavior, pub allowed_buttons_filter: Option<AllowedButtonsFilter>,
}
Expand description

A widget that can be dragged from to a DragTarget.

Active drags and their feedback survive removal of the source widget.

Fields§

§key: Option<KeyRef>

Controls how one widget replaces another widget in the tree.

§data: Option<Rc<T>>

The data that was dropped onto this DragTarget.

§axis: Option<Axis>

The Axis to restrict this draggable’s movement, if specified.

When axis is set to Axis.horizontal, this widget can only be dragged horizontally. Behavior is similar for Axis.vertical.

Defaults to allowing drag on both Axis.horizontal and Axis.vertical.

When null, allows drag on both Axis.horizontal and Axis.vertical.

For the direction of gestures this widget competes with to start a drag event, see Draggable.affinity.

§child: WidgetRef

The widget below this widget in the tree.

This widget displays child when zero drags are under way. If childWhenDragging is non-null, this widget instead displays childWhenDragging when one or more drags are underway. Otherwise, this widget always displays child.

The feedback widget is shown under the pointer when a drag is under way.

To limit the number of simultaneous drags on multitouch devices, see maxSimultaneousDrags.

{@macro flutter.widgets.ProxyWidget.child}

§child_when_dragging: Option<WidgetRef>

The widget to display instead of child when one or more drags are under way.

If this is null, then this widget will always display child (and so the drag source representation will not change while a drag is under way).

The feedback widget is shown under the pointer when a drag is under way.

To limit the number of simultaneous drags on multitouch devices, see maxSimultaneousDrags.

§feedback: WidgetRef

The widget to show under the pointer when a drag is under way.

See child and childWhenDragging for information about what is shown at the location of the Draggable itself when a drag is under way.

§feedback_offset: Offset

The feedbackOffset can be used to set the hit test target point for the purposes of finding a drag target. It is especially useful if the feedback is transformed compared to the child.

§drag_anchor_strategy: DragAnchorStrategy<T>

A strategy that is used by this draggable to get the anchor offset when it is dragged.

The anchor offset refers to the distance between the users’ fingers and the feedback widget when this draggable is dragged.

This property’s value is a function that implements DragAnchorStrategy. There are two built-in functions that can be used:

  • childDragAnchorStrategy, which displays the feedback anchored at the position of the original child.

  • pointerDragAnchorStrategy, which displays the feedback anchored at the position of the touch that started the drag.

Defaults to childDragAnchorStrategy.

§ignoring_feedback_semantics: bool

Whether the semantics of the feedback widget is ignored when building the semantics tree.

This value should be set to false when the feedback widget is intended to be the same object as the child. Placing a GlobalKey on this widget will ensure semantic focus is kept on the element as it moves in and out of the feedback position.

Defaults to true.

§ignoring_feedback_pointer: bool

Whether the feedback widget is ignored during hit testing.

Regardless of whether this widget is ignored during hit testing, it will still consume space during layout and be visible during painting.

Defaults to true.

§affinity: Option<Axis>

Controls how this widget competes with other gestures to initiate a drag.

If affinity is null, this widget initiates a drag as soon as it recognizes a tap down gesture, regardless of any directionality. If affinity is horizontal (or vertical), then this widget will compete with other horizontal (or vertical, respectively) gestures.

For example, if this widget is placed in a vertically scrolling region and has horizontal affinity, pointer motion in the vertical direction will result in a scroll and pointer motion in the horizontal direction will result in a drag. Conversely, if the widget has a null or vertical affinity, pointer motion in any direction will result in a drag rather than in a scroll because the draggable widget, being the more specific widget, will out-compete the Scrollable for vertical gestures.

For the directions this widget can be dragged in after the drag event starts, see Draggable.axis.

§max_simultaneous_drags: Option<usize>

How many simultaneous drags to support.

When null, no limit is applied. Set this to 1 if you want to only allow the drag source to have one item dragged at a time. Set this to 0 if you want to prevent the draggable from actually being dragged.

If you set this property to 1, consider supplying an “empty” widget for childWhenDragging to create the illusion of actually moving child.

§on_drag_started: Option<Listener>

Called when the draggable starts being dragged.

§on_drag_update: Option<DragUpdateCallback>

Called when the draggable is dragged.

This function will only be called while this widget is still mounted to the tree (i.e. State.mounted is true), and if this widget has actually moved.

§on_draggable_canceled: Option<DraggableCanceledCallback>

Called when the draggable is dropped without being accepted by a DragTarget.

This function might be called after this widget has been removed from the tree. For example, if a drag was in progress when this widget was removed from the tree and the drag ended up being canceled, this callback will still be called. For this reason, implementations of this callback might need to check State.mounted to check whether the state receiving the callback is still in the tree.

§on_drag_completed: Option<Listener>

Called when the draggable is dropped and accepted by a DragTarget.

This function might be called after this widget has been removed from the tree. For example, if a drag was in progress when this widget was removed from the tree and the drag ended up completing, this callback will still be called. For this reason, implementations of this callback might need to check State.mounted to check whether the state receiving the callback is still in the tree.

§on_drag_end: Option<DragEndCallback>

Called when the draggable is dropped.

The velocity and offset at which the pointer was moving when it was dropped is available in the DraggableDetails. Also included in the details is whether the draggable’s DragTarget accepted it.

This function will only be called while this widget is still mounted to the tree (i.e. State.mounted is true).

§root_overlay: bool

Whether the feedback widget will be put on the root Overlay.

When false, the feedback widget will be put on the closest Overlay. When true, the feedback widget will be put on the farthest (aka root) Overlay.

Defaults to false.

§hit_test_behavior: HitTestBehavior

How to behave during hit testing.

Defaults to HitTestBehavior.translucent.

§allowed_buttons_filter: Option<AllowedButtonsFilter>

{@macro flutter.gestures.multidrag._allowedButtonsFilter}

Implementations§

Source§

impl<T: 'static> Draggable<T>

Source

pub fn new<C, F>( child: impl IntoWidget<C>, feedback: impl IntoWidget<F>, ) -> Self

Creates a draggable with its normal child and drag feedback.

Source

pub fn key(self, value: KeyRef) -> Self

Sets key for this draggable.

Source

pub fn data(self, value: T) -> Self

Sets data for this draggable.

Source

pub fn axis(self, value: Axis) -> Self

Sets axis for this draggable.

Source

pub fn child_when_dragging<K>(self, value: impl IntoWidget<K>) -> Self

Sets child_when_dragging for this draggable.

Source

pub fn feedback_offset(self, value: Offset) -> Self

Sets feedback_offset for this draggable.

Source

pub fn drag_anchor_strategy(self, value: DragAnchorStrategy<T>) -> Self

Sets drag_anchor_strategy for this draggable.

Source

pub fn ignoring_feedback_semantics(self, value: bool) -> Self

Sets ignoring_feedback_semantics for this draggable.

Source

pub fn ignoring_feedback_pointer(self, value: bool) -> Self

Sets ignoring_feedback_pointer for this draggable.

Source

pub fn affinity(self, value: Axis) -> Self

Sets affinity for this draggable.

Source

pub fn max_simultaneous_drags(self, value: usize) -> Self

Sets max_simultaneous_drags for this draggable.

Source

pub fn on_drag_started(self, value: Listener) -> Self

Sets on_drag_started for this draggable.

Source

pub fn on_drag_update(self, value: DragUpdateCallback) -> Self

Sets on_drag_update for this draggable.

Source

pub fn on_draggable_canceled(self, value: DraggableCanceledCallback) -> Self

Sets on_draggable_canceled for this draggable.

Source

pub fn on_drag_completed(self, value: Listener) -> Self

Sets on_drag_completed for this draggable.

Source

pub fn on_drag_end(self, value: DragEndCallback) -> Self

Sets on_drag_end for this draggable.

Source

pub fn root_overlay(self, value: bool) -> Self

Sets root_overlay for this draggable.

Source

pub fn hit_test_behavior(self, value: HitTestBehavior) -> Self

Sets hit_test_behavior for this draggable.

Source

pub fn allowed_buttons_filter(self, value: AllowedButtonsFilter) -> Self

Sets allowed_buttons_filter for this draggable.

Trait Implementations§

Source§

impl<T: 'static> Clone for Draggable<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: 'static> Debug for Draggable<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: 'static> DraggableWidget for Draggable<T>

Source§

impl<T: 'static> StatefulWidget for Draggable<T>

Source§

type State = DraggableState<Draggable<T>>

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn create_state(&self) -> Self::State

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn debug_check_constructor(&self)

Source§

fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>

Source§

fn type_name(&self) -> &'static str

See Widget::type_name. A stateful form another widget kind becomes (an animated or status transition widget) names the widget it wraps.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Draggable<T>

§

impl<T> !Send for Draggable<T>

§

impl<T> !Sync for Draggable<T>

§

impl<T> !UnwindSafe for Draggable<T>

§

impl<T> Forget for Draggable<T>

§

impl<T> Freeze for Draggable<T>
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<T> is !null: Freeze, PhantomData<RcInner<T>>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze, *const RcInner<dyn Fn(&mut App, &Draggable<T>, AnyElement, Offset) -> Offset> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, &Draggable<T>, AnyElement, Offset) -> Offset>>: Freeze, *const RcInner<dyn Fn(&mut App)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App)>>: Freeze, NonZero<u32>: Freeze, *const (): Freeze, *const RcInner<dyn Fn(&mut App, DragUpdateDetails)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, DragUpdateDetails)>>: Freeze, *const RcInner<dyn Fn(&mut App, Velocity, Offset)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, Velocity, Offset)>>: Freeze, *const RcInner<dyn Fn(&mut App, DraggableDetails)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, DraggableDetails)>>: Freeze, *const RcInner<dyn Fn(i64) -> bool> is !null: Freeze, PhantomData<RcInner<dyn Fn(i64) -> bool>>: Freeze,

§

impl<T> Move for Draggable<T>

§

impl<T> Unpin for Draggable<T>
where Rc<dyn Key>: Unpin, Rc<T>: Unpin, Rc<dyn Widget>: Unpin, Rc<dyn Fn(&mut App, &Draggable<T>, AnyElement, Offset) -> Offset>: Unpin, Rc<dyn Fn(&mut App)>: Unpin, NonZero<u32>: Unpin, *const (): Unpin, Rc<dyn Fn(&mut App, DragUpdateDetails)>: Unpin, Rc<dyn Fn(&mut App, Velocity, Offset)>: Unpin, Rc<dyn Fn(&mut App, DraggableDetails)>: Unpin, Rc<dyn Fn(i64) -> bool>: Unpin,

§

impl<T> UnsafeUnpin for Draggable<T>
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const RcInner<T> is !null: UnsafeUnpin, PhantomData<RcInner<T>>: UnsafeUnpin, *const RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, &Draggable<T>, AnyElement, Offset) -> Offset> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, &Draggable<T>, AnyElement, Offset) -> Offset>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App)>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, *const (): UnsafeUnpin, *const RcInner<dyn Fn(&mut App, DragUpdateDetails)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, DragUpdateDetails)>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, Velocity, Offset)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, Velocity, Offset)>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, DraggableDetails)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, DraggableDetails)>>: UnsafeUnpin, *const RcInner<dyn Fn(i64) -> bool> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(i64) -> bool>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<W> IntoWidget<StatefulKind> for W
where W: StatefulWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>