Skip to content

Commit

Permalink
Update pressable_widget.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
tilucasoli committed Jan 31, 2024
1 parent 0a600d5 commit 5dc526c
Showing 1 changed file with 34 additions and 40 deletions.
74 changes: 34 additions & 40 deletions lib/src/widgets/pressable/pressable_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,54 +154,48 @@ class PressableWidgetState extends State<Pressable> {

final onEnabled = currentStatus == WidgetStatus.enabled;

final focusableDetector = FocusableActionDetector(
enabled: onEnabled,
focusNode: _node,
autofocus: widget.autofocus,
onShowFocusHighlight: (v) => updateState(() => _focus = v),
onShowHoverHighlight: (v) => updateState(() => _hover = v),
onFocusChange: widget.onFocusChange,
child: WidgetStateNotifier(
data: WidgetStateData(
focus: _focus,
status: currentStatus,
state: currentGesture,
hover: _hover,
),
child: widget.child,
),
);

return MergeSemantics(
child: Semantics(
enabled: onEnabled,
button: true,
focusable: onEnabled && _node.canRequestFocus,
focused: _node.hasFocus,
child: _buildGestureDetector(
isDisabled: widget.disabled,
child: FocusableActionDetector(
enabled: onEnabled,
focusNode: _node,
autofocus: widget.autofocus,
onShowFocusHighlight: (v) => updateState(() => _focus = v),
onShowHoverHighlight: (v) => updateState(() => _hover = v),
onFocusChange: widget.onFocusChange,
child: WidgetStateNotifier(
data: WidgetStateData(
focus: _focus,
status: currentStatus,
state: currentGesture,
hover: _hover,
),
child: widget.child,
child: widget.disabled
? GestureDetector(
child: focusableDetector,
)
: GestureDetector(
onTapDown: (_) => updateState(() => _pressed = true),
onTapUp: (_) => handleUnpress(),
onTap: widget.onPressed,
onTapCancel: () => handleUnpress(),
onLongPressCancel: () =>
updateState(() => _longpressed = false),
onLongPress: widget.onLongPress,
onLongPressStart: (_) => updateState(() => _longpressed = true),
onLongPressEnd: (_) => updateState(() => _longpressed = false),
behavior: widget.behavior,
child: focusableDetector,
),
)),
),
);
}

GestureDetector _buildGestureDetector({
required bool isDisabled,
required Widget child,
}) {
return isDisabled
? GestureDetector(
child: child,
)
: GestureDetector(
onTapDown: (_) => updateState(() => _pressed = true),
onTapUp: (_) => handleUnpress(),
onTap: widget.onPressed,
onTapCancel: () => handleUnpress(),
onLongPressCancel: () => updateState(() => _longpressed = false),
onLongPress: widget.onLongPress,
onLongPressStart: (_) => updateState(() => _longpressed = true),
onLongPressEnd: (_) => updateState(() => _longpressed = false),
behavior: widget.behavior,
child: child,
);
}
}

0 comments on commit 5dc526c

Please sign in to comment.