Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

dart - Flutter AbsorbPointer vs IgnorePointer difference

What is the difference between AbsorbPointer and IgnorePointer in flutter?

Docs mention:

AbsorbPointer prevents its subtree from receiving pointer events by terminating hit testing at itself.

IgnorePointer, which also prevents its children from receiving pointer events but is itself invisible to hit testing.

I didn't get what is the real life difference between the two.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The difference is when we have two widgets overlapping each other, 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, tapping the blue square will 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 square, neither the blue square nor the red one gets the click event.

If we instead used an IgnorePointer, the red square would receive click events when tapping the blue square.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...