Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.stac.dev/llms.txt

Use this file to discover all available pages before exploring further.

The GestureDetector widget in Stac allows you to detect various gestures and user interactions within your application. It wraps Flutter’s native GestureDetector widget, providing a JSON-based interface to handle touch events, taps, drags, and more.

Usage

To use a GestureDetector in your Stac, specify the widget type as “gestureDetector” and provide a child widget along with any gesture callbacks you want to handle.
StacGestureDetector(
  child: StacContainer(
    color: StacColors.blue,
    width: 200,
    height: 200,
    alignment: StacAlignment.center,
    child: StacText(
      data: 'Tap me!',
      style: StacTextStyle(color: StacColors.white, fontSize: 20),
    ),
  ),
  onTap: StacSnackBarAction(
    content: StacText(data: 'This is a Snackbar'),
  ),
)

Properties

Child Widget

PropertyTypeDescription
childStacWidgetThe widget that will respond to gestures

Tap Gestures

PropertyTypeDescription
onTapDownStacActionCalled when a pointer contacts the screen
onTapUpStacActionCalled when a pointer stops contacting the screen
onTapStacActionCalled when a tap occurs
onTapCancelStacActionCalled when the tap is canceled
onDoubleTapDownStacActionCalled when a pointer contacts the screen in a potential double tap
onDoubleTapStacActionCalled when a double tap occurs
onDoubleTapCancelStacActionCalled when the double tap is canceled

Secondary and Tertiary Tap Gestures

PropertyTypeDescription
onSecondaryTapStacActionCalled when a secondary tap occurs (e.g., right-click)
onSecondaryTapDownStacActionCalled when a secondary pointer contacts the screen
onSecondaryTapUpStacActionCalled when a secondary pointer stops contacting the screen
onSecondaryTapCancelStacActionCalled when the secondary tap is canceled
onTertiaryTapDownStacActionCalled when a tertiary pointer contacts the screen
onTertiaryTapUpStacActionCalled when a tertiary pointer stops contacting the screen
onTertiaryTapCancelStacActionCalled when the tertiary tap is canceled

Long Press Gestures

PropertyTypeDescription
onLongPressDownStacActionCalled when a pointer contacts the screen in a potential long press
onLongPressCancelStacActionCalled when the long press is canceled
onLongPressStacActionCalled when a long press occurs
onLongPressStartStacActionCalled when a long press starts
onLongPressMoveUpdateStacActionCalled when a long press move update occurs
onLongPressUpStacActionCalled when a long press up occurs
onLongPressEndStacActionCalled when a long press ends

Secondary and Tertiary Long Press Gestures

PropertyTypeDescription
onSecondaryLongPressDownStacActionCalled when a secondary pointer contacts the screen in a potential long press
onSecondaryLongPressCancelStacActionCalled when the secondary long press is canceled
onSecondaryLongPressStacActionCalled when a secondary long press occurs
onSecondaryLongPressStartStacActionCalled when a secondary long press starts
onSecondaryLongPressMoveUpdateStacActionCalled when a secondary long press move update occurs
onSecondaryLongPressUpStacActionCalled when a secondary long press up occurs
onSecondaryLongPressEndStacActionCalled when a secondary long press ends
onTertiaryLongPressDownStacActionCalled when a tertiary pointer contacts the screen in a potential long press
onTertiaryLongPressCancelStacActionCalled when the tertiary long press is canceled
onTertiaryLongPressStacActionCalled when a tertiary long press occurs
onTertiaryLongPressStartStacActionCalled when a tertiary long press starts
onTertiaryLongPressMoveUpdateStacActionCalled when a tertiary long press move update occurs
onTertiaryLongPressUpStacActionCalled when a tertiary long press up occurs
onTertiaryLongPressEndStacActionCalled when a tertiary long press ends

Drag Gestures

PropertyTypeDescription
onVerticalDragDownStacActionCalled when a pointer contacts the screen and might begin a vertical drag
onVerticalDragStartStacActionCalled when a pointer starts a vertical drag
onVerticalDragUpdateStacActionCalled when a pointer updates a vertical drag
onVerticalDragEndStacActionCalled when a pointer ends a vertical drag
onVerticalDragCancelStacActionCalled when the vertical drag is canceled
onHorizontalDragDownStacActionCalled when a pointer contacts the screen and might begin a horizontal drag
onHorizontalDragStartStacActionCalled when a pointer starts a horizontal drag
onHorizontalDragUpdateStacActionCalled when a pointer updates a horizontal drag
onHorizontalDragEndStacActionCalled when a pointer ends a horizontal drag
onHorizontalDragCancelStacActionCalled when the horizontal drag is canceled

Force Press Gestures

PropertyTypeDescription
onForcePressStartStacActionCalled when a force press starts
onForcePressPeakStacActionCalled when a force press reaches its peak force
onForcePressUpdateStacActionCalled when a force press updates
onForcePressEndStacActionCalled when a force press ends

Other Properties

PropertyTypeDefaultDescription
excludeFromSemanticsboolfalseWhether to exclude the gestures from the semantics tree
dragStartBehaviorStacDragStartBehaviorstartDetermines when a drag formally starts

Examples

Simple Tap Example

StacGestureDetector(
  onTap: StacNavigateAction(routeName: '/details'),
  child: StacContainer(
    padding: StacEdgeInsets.all(16),
    color: StacColors.grey,
    child: StacText(data: 'Navigate to Details'),
  ),
)

Drag Example

StacGestureDetector(
  onHorizontalDragEnd: {'actionType': 'handleSwipe'},
  child: StacContainer(
    width: 200,
    height: 200,
    color: StacColors.grey,
    alignment: StacAlignment.center,
    child: StacText(data: 'Swipe horizontally'),
  ),
)

Long Press Example

StacGestureDetector(
  onLongPress: StacDialogAction(
    title: 'Long Press Detected',
    content: StacText(data: 'You performed a long press on the widget.'),
  ),
  child: StacContainer(
    padding: StacEdgeInsets.all(16),
    decoration: StacBoxDecoration(color: StacColors.green, borderRadius: StacBorderRadius.all(8)),
    child: StacText(
      data: 'Long press me',
      style: StacTextStyle(color: StacColors.white),
    ),
  ),
)

Action Handling

Each gesture callback in Stac GestureDetector accepts an action object that defines what should happen when the gesture is detected. This can be a navigation action, showing a dialog, executing a custom function, or any other action supported by your Stac application. For more information on actions, see the Actions documentation.