IgnorePointer & AbsorbPointer

What if you want to disable the touch in a certain area or in other word, you want to make the touch pointer has no effect. In Flutter, you can use IgnorePointer or AbsorbPointer.

 IgnorePointer(
    ignoring: true,
    child: MyWidget(),
  )

If ignoring value is true, any click inside the widget will be ignored. By default the value is true. You can use this property to dynamically toggle the behaviour. If you set ignoring to false dynamically, the child will now will respont to touch.

AbsorbPointer is a kind of control that forbids user input, such as button click, input of input box, scrolling of ListView, etc. you may say that setting the onPressed of button to null can also be realized, yes, but AbsorbPointer can provide unified control of multiple components without requiring you to set each component separately.

 AbsorbPointer(
    absorbing: true,
    child: MyWidget(),
  )

If absorbing value is true, any click inside the widget will be absorbed. If you don't pass absorbing parameter, it will use the default value (true) which causes any pointer inside the widget will be absorbed.

Difference Between IgnorePoiner and AbsorbPointer

The difference is when we have two widgets overlapping each other's, that can both receive clicks. Consider a red and blue square, both clickable, where the blue square is smaller and on the top of the red square:

Stack(
  alignment: Alignment.center,
  children: [
     Container(color: Colors.red),
     Container(width: 42, height: 42, color: Colors.blue),
  ],
)

By default, without IgnorePointer/AbsorbPointer, taping blue send a click event on blue and red gets nothing.

In that situation, wrapping blue square into an AbsorbPointer means that when tapping the blue zone, neither the blue square nor the red one gets the click event. That means the the event will be absorbed totally and will not pass to any widget.

If we instead used an IgnorePointer, the red square would receive click events when taping the blue square. That means the event will be passed down to the widget that below the widget.