All applications now use touch input from the user. In some cases, you may need to disable touch in certain areas or prevent the touch pointer from working. In Flutter, you can use IgnorePointer Widget or AbsorbPointer Widget to ignore the touch events.
You may also check our Flutter app development services.
1. IgnorePointer Widget : IgnorePointer is a built-in widget that protects your child’s widgets from pointer events such as taps, drags, scrolls, and hovers. This widget ignores pointer events without terminating them. This widget is used to prevent unnecessary touch of UI. It is very simple just wrap your widget inside the IgnorePointer widget.
- Properties :
- key: The widget key, used to control if it’s should be replaced.
- ignoring: Whether this widget is ignored during hit testing. Defaults to true.
- ignoringSemantics: Whether the semantics of this widget is ignored when compiling the semantics tree.
- child: The widget to be rendered.
2. AbsorbPointer Widget: AbsorbPointer is a built-in widget in Flutter that absorbs pointers. The main reason this widget exists is to provide the ability to disable the interaction of its subtree widgets at once. In flutter, most widgets currently accompany an alternative to impair them.
- Properties :
- key: The widget Key used to control if it should be replaced.
- absorbing: Absorbing Property is used to define whether this widget absorbs during the touch events. The default value is set to true. If the absorbing value is true, and click inside the widget will be absorbed.
- ignoringSemantics: ignoringSemantics Property is used to define whether the semantics of this widget is ignored when compiling the semantics tree.
- child: Child Property is used to define widgets under current Widget in a tree. It has only one Child.
Difference between AbsorbPointer and IgnorePointer:
If you have widgets below the main widget that can also receive click events, and you use IgnorePointer on the parent widget, the child widgets will still receive click events.
However, using AbsorbPointer on the main widget prevents other widgets below the main widget from receiving that click event.
If you have widgets under the main widget that can also receive click events, and you use IgnorePointer on the parent widget, the child widgets will still receive click events.
But using AbsorbPointer in the main widget prevents other widgets below the main widget from receiving that click event.
Conclusion:
In the article, We have discussed two widgets that used to ignore the touch event in flutter. This was a small introduction to AbsorbPointer and IgnorePointer widgets. I hope this blog will help you to understand these widgets.
Thanks for reading!!