CLI Setup: If you create a new Neo project using the Neo CLI, NeoHaptics will be automatically initialized for you in
main.dart
through the NeoInitializer.initialize()
call.Examples
- Basic Usage
- Form Interactions
Platform Support
NeoHaptics provides different levels of haptic feedback across platforms:iOS: Full support with Apple Pencil integration and Core Haptics engine for sophisticated tactile patterns.macOS: Trackpad haptic feedback for built-in MacBook trackpads and Magic Trackpads. By default, haptic feedback is disabled on macOS trackpads to prevent excessive feedback during typical interactions, since trackpads already provide haptic feedback when clicking. You can override this behavior using the
enableMacOS
parameter on individual methods when needed (e.g., for dragging interactions or snapping feedback while already holding down the trackpad).Android: Fallback to Flutter’s built-in haptic feedback system using device vibration motor.Web: Haptics are not supported and calls are safely ignored.Methods
NeoHaptics.initialize()
Initializes the haptic feedback system. This method is automatically called byNeoInitializer.initialize()
and typically shouldn’t be called manually.
Return Value
A Future that completes when the haptic system has been initialized for the current platform.
NeoHaptics.light()
Provides subtle haptic feedback, ideal for lightweight interactions like toggles, selections, or confirmations.Optional Parameters
Whether to enable haptic feedback on macOS trackpads. See Platform Support for details about macOS haptic behavior.
Return Value
A Future that completes when the haptic feedback has been triggered.
NeoHaptics.heavy()
Provides strong haptic feedback for significant interactions like completion of major actions, navigation changes, or important confirmations.Optional Parameters
Whether to enable haptic feedback on macOS trackpads. See Platform Support for details about macOS haptic behavior.
Return Value
A Future that completes when the haptic feedback has been triggered.
NeoHaptics.error()
Provides distinctive error haptic feedback as a triple-tap pattern with decreasing intensity, perfect for validation errors, failed operations, or warning states.Return Value
A Future that completes when the error haptic sequence has been triggered.
Best Practices
- Match Interaction Weight: Use
light()
for subtle interactions,heavy()
for significant actions, anderror()
for problems or failures. - Avoid Overuse: Haptic feedback should enhance interactions, not overwhelm them. Not every tap needs haptic feedback.
Integration Notes
- Error Handling: All haptic calls are wrapped in try-catch blocks and failures are logged via NeoLogger without throwing exceptions.