简体   繁体   中英

Flutter prevent click through widget

How can I make a clickable widget with a ripple and a button inside?

Here is the code I have:

          Material(
              child: InkWell(
                onTap: () {},
                child: Column(
                  children: <Widget>[
                    Text("this column is clickable"),
                    IconButton(
                      icon: Icon(Icons.airplanemode_active),
                      onPressed: () {},
                    ),
                  ]
                )
              )
            ),

When clicking on the Column, everything works fine, the ripple effect go behind the IconButton as expected. But when clicking on the IconButton, the onPressed trigger is called but it also activates the InkWell. Is there a way to prevent in from activation the InkWell?

Put Column widget inside GestureDetector and set excludeFromSemantics: true like the following:

Material(
  child: Padding(
    padding: const EdgeInsets.all(40.0),
    child: InkWell(
      onTap: () {},
      child: GestureDetector(
        excludeFromSemantics: true,
        child: Column(
          children: <Widget>[
            Text("this column is clickable"),
            IconButton(
              icon: Icon(Icons.airplanemode_active),
              onPressed: () {},
            ),
          ]
        ),
      )
    ),
  )
),

Its from this github post.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM