ArnaFeedback class
Provides platform-specific acoustic and/or haptic feedback for certain actions.
For the Android-specific vibration when long pressing an element, call forLongPress. Alternatively, you can also wrap your GestureDetector.onLongPress callback in wrapForLongPress to achieve the same.
Calling any of these methods is a no-op on iOS as actions on that platform typically don't provide haptic feedback.
All methods in this class are usually called from within a StatelessWidget.build method or from a State's methods as you have to provide a BuildContext.
{@tool snippet}
To trigger platform-specific feedback before executing the actual callback:
class WidgetWithWrappedHandler extends StatelessWidget {
const WidgetWithWrappedHandler({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return GestureDetector(
onLongPress: ArnaFeedback.wrapForLongPress(_onLongPressHandler, context),
child: const Text('X'),
);
}
void _onLongPressHandler() {
// Respond to long press.
}
}
{@end-tool} {@tool snippet}
Alternatively, you can also call forLongPress directly within your long press handler:
class WidgetWithExplicitCall extends StatelessWidget {
const WidgetWithExplicitCall({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return GestureDetector(
onLongPress: () {
// Do some work (e.g. check if the long press is valid)
ArnaFeedback.forLongPress(context);
// Do more work (e.g. respond to the long press)
},
child: const Text('X'),
);
}
}
{@end-tool}
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 Methods
-
forLongPress(
BuildContext context) → Future< void> - Provides platform-specific feedback for a long press.
-
wrapForLongPress(
GestureLongPressCallback? callback, BuildContext context) → GestureLongPressCallback? - Wraps a GestureLongPressCallback to provide platform specific feedback for a long press before the provided callback is executed.