Dpad class final
Utility class providing convenient methods for programmatic D-pad navigation.
This class offers static methods for controlling focus behavior programmatically, allowing you to navigate, request focus, and manage focus state without requiring user interaction with D-pad controls.
Example Usage:
// Get current focus
final currentFocus = Dpad.currentFocus;
// Navigate programmatically
Dpad.navigateUp(context);
Dpad.navigateDown(context);
Dpad.navigateLeft(context);
Dpad.navigateRight(context);
// Request specific focus
Dpad.requestFocus(myFocusNode);
// Clear all focus
Dpad.clearFocus();
// Focus memory utilities (requires context for navigator-scoped history)
final previousEntry = Dpad.getPreviousFocus(context);
final currentEntry = Dpad.getCurrentFocusEntry(context);
final history = Dpad.getFocusHistory(context);
Use Cases:
- Automatic focus management on screen changes
- Focus restoration after dialogs
- Programmatic navigation in response to gestures
- Custom navigation logic beyond D-pad controls
- Focus memory management and restoration
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- currentFocus → FocusNode?
-
Gets the currently focused widget's FocusNode.
no setter
Static Methods
-
clearFocus(
) → void - Clears focus from the currently focused widget.
-
clearFocusHistory(
BuildContext context) → void - Clears all focus history entries and resets the memory state.
-
getCurrentFocusEntry(
BuildContext context) → FocusHistoryEntry? - Gets the current focus entry with complete information.
-
getFocusHistory(
BuildContext context) → List< FocusHistoryEntry> - Gets the complete focus history as a list.
-
getPreviousFocus(
BuildContext context) → FocusHistoryEntry? - Gets the previous focus entry for memory restoration.
- Navigates focus downward.
- Navigates focus in the specified direction.
- Navigates focus leftward.
- Navigates focus to the next widget in the focus traversal order.
- Navigates focus to the previous widget in the focus traversal order.
- Navigates focus rightward.
- Navigates focus upward.
-
requestFocus(
FocusNode? focusNode) → bool - Requests focus on the specified FocusNode.
-
requestFocusSafely(
FocusNode? focusNode) → bool - Safely requests focus on a FocusNode with validation.
-
scrollToFocus(
FocusNode focusNode, {double padding = 24.0, Duration duration = const Duration(milliseconds: 300), Curve curve = Curves.easeOutCubic}) → void - Scrolls to ensure the focused widget is fully visible with proper padding.