mosh.jinton
mosh.jinton

Reputation: 328

Interact with widget in Stack with translucent widget covering it

I have a Widget which I want to 'fade out' at the bottom, so I've put it into a Stack with a Container on top of it, with the appropriate gradient as the Container's background. However, the container seems to be consuming all touch events, so I can't interact with the Widget behind it, which is not desirable because the Widget is still mostly visible. Is there any way to change this behaviour?

Upvotes: 6

Views: 1233

Answers (3)

Canada2000
Canada2000

Reputation: 1698

Here is how to do that:

Code:

IgnorePointer(
  child: YourContainerWidget)

or, depending on your exact objective, you may want to try this:

AbsorbPointer(
  child: YourContainerWidget)

See more info here

Upvotes: 9

Mordtimer
Mordtimer

Reputation: 1

You can warp your widget with Visibility. This solution will not remove your widget from the tree, so You can easily reuse it later. However, you should consider if it will just not be better to remove it from the widget tree.

    Visibility(
      visible: _isVisible
      child: FooWidget(),
    )

Upvotes: 0

Pat9RB
Pat9RB

Reputation: 650

Once the widget is fully transparent you can remove it from the UI tree with an if() or ternary, i.e: if(opacity != 0) YourWidget() or opacity == 0 ? SizedBox() : YourWidget()

You can also wrap it with an IgnorePointer() widget.

Upvotes: 0

Related Questions