Skip to Content
Mix 2.0 is in development! You can access the Mix 1.0 docs here.
DocsWidgetsPressable

Pressable

This is equivalent to Flutter’s GestureDetector, MouseRegion, and Focus widgets but with enhanced interaction state management and styling capabilities.

Pressable( onPress: () => print('Pressed!'), child: StyledText('Press Me'), );

Constructor

PropTypeRequired / Default Value
childWidgetRequired
enabledboolOptional, defaults to true
enableFeedbackboolOptional, defaults to false
onPressVoidCallback?Optional
onLongPressVoidCallback?Optional
onFocusChangeValueChanged<bool>?Optional
hitTestBehaviorHitTestBehaviorOptional, defaults to HitTestBehavior.opaque
autofocusboolOptional, defaults to false
focusNodeFocusNode?Optional
mouseCursorMouseCursor?Optional
canRequestFocusboolOptional, defaults to true
excludeFromSemanticsboolOptional, defaults to false
semanticButtonLabelString?Optional
controllerWidgetStatesController?Optional
actionsMap<Type, Action<Intent>>?Optional
keyKey?Optional

Usage Examples

Pressable with Focus and Long Press

Pressable( onPress: () => print('Pressed'), onLongPress: () => print('Long pressed'), onFocusChange: (focused) => print('Focus: $focused'), autofocus: true, child: StyledText('Interactive Button'), );

Disabled Pressable

Pressable( enabled: false, onPress: () => print('This won\'t be called'), child: StyledText('Disabled Button'), );

PressableBox

PressableBox combines the functionality of Pressable with Box styling capabilities, providing a pressable area with customizable visual styling.

PressableBox( style: BoxStyler() .color(Colors.blue) .paddingAll(16) .borderRounded(8), onPress: () => print('PressableBox pressed'), child: StyledText('Styled Button'), );

PressableBox Constructor

PropTypeRequired / Default Value
childWidgetRequired
styleBoxStyler?Optional
enabledboolOptional, defaults to true
enableFeedbackboolOptional, defaults to false
onPressVoidCallback?Optional
onLongPressVoidCallback?Optional
onFocusChangeFunction(bool)?Optional
hitTestBehaviorHitTestBehaviorOptional, defaults to HitTestBehavior.opaque
autofocusboolOptional, defaults to false
focusNodeFocusNode?Optional
keyKey?Optional

PressableBox with Interaction States

PressableBox integrates with Mix’s variant system to apply different styles based on interaction states:

PressableBox( style: BoxStyler() .color(Colors.blue) .padding(16) .borderRadius(8) .onPressed(BoxStyler().color(Colors.red)) .onHovered(BoxStyler().color(Colors.green)) .onFocused(BoxStyler().border(Border.all(color: Colors.white, width: 2))) .onDisabled(BoxStyler().color(Colors.grey)), onPress: () => print('Interactive button pressed'), child: StyledText('Interactive Button'), );

Available Interaction States

StateDescription
onPressedStyles applied when the widget is being pressed
onLongPressedStyles applied when the widget is being long-pressed
onHoveredStyles applied when a pointer hovers over the widget
onFocusedStyles applied when the widget gains focus
onDisabledStyles applied when the widget is disabled
onEnabledStyles applied when the widget is enabled and interactive