I want to have a blurred image on top of my other widgets, however, I cannot interact with the widgets below it when I do that.
AbsorbPointer Widget What we have to do is to wrap the widget we want to disable touch with this Widget. This widget has a property called absorbing . If this is set to true, the touch will be disabled for the child widgets.
The stack is a widget in Flutter. It contains a list of widgets and places them on top of each other. And it places their children on top of each other like a stack of books. In other words, stack developers would overlap multiple widgets on one screen. As you can add different images or colors using containers in it.
IgnorePointer is a built-in widget in flutter which is similar to the AbsorbPointer widget, they both prevent their children's widget from pointer-events which are taping, clicking, dragging, scrolling, and hover.
AbsorbPointer is a built-in widget in flutter which absorbs pointer, in other words, it prevents its subtree from being clicked, tapped, scrolled, dragged, and responding to hover.
You can solve your interaction issue (not being able to interact with the Widget
below your blurred image) by surrounding your BackdropFilter
with an IgnorePointer
.
This means that IgnorePointer
is the solution here because it will ignore all touch events for the Widget
's passed as its child.
IgnorePointer(child: BackdropFilter(...),)
You can adjust this attribute by changing the bool
value of ignoring
:
IgnorePointer(ignoring: false, ...)
This will enable all touch events again.
Something interesting to look at here, but unrelated to the problem, is the AbsorbPointer
Widget
, which can be used to reflect all touch events that occur on its child onto itself.
You can either use IgnorePointer
or AbsorbPointer
.
IgnorePointer
IgnorePointer( child: ElevatedButton( onPressed: () {}, child: Text('Not clickable Button'), ), );
AbsorbPointer
AbsorbPointer( child: ElevatedButton( onPressed: () {}, child: Text('Not clickable Button'), ), );
What's the difference?
If there is a widget beneath your main widget which is also capable of receiving click events, and you use IgnorePointer
on the parent widget, the child widget would still receive the click events.
But using AbsorbPointer
on main widget won't allow the other widget (beneath main widget) to receive their click events.
Example showing the difference.
@override Widget build(BuildContext context) { return SizedBox( width: double.infinity, child: Stack( children: <Widget>[ Positioned( left: 0, width: 250, child: ElevatedButton( color: Colors.red, onPressed: () => print("Button 1"), child: Text("Button 1"), ), ), Positioned( right: 0, width: 250, child: IgnorePointer( // replace this with AbsorbPointer and button 1 won't receive click child: ElevatedButton( onPressed: () => print("Button 2"), child: Text("Button 2"), ), ), ), ], ), ); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With