Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to disable clicks detection in a CheckBox that's wrapped by an InkWell in Flutter

I have those 4 Inkwell(), inside each of them is a CheckBox(),
In the onTap: property of the InkWell() I assigned an unnamed function that does some logic.
When I click on the checkbox, the ‘onTap’ property of the parent InkWell isn’t invoked.

What I wanna do, is when I click on the CheckBox, the onTap of the parent widget InkWell get called, so it’s like disabling the CheckBox onChanged property, and letting it just like an unclickable widget.

Note: By assigning null to the onChanged property of CheckBox, the widget still absorb the click, so the onTap property of InkWell doesn’t get called.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

Here is my code:

InkWell(
  onTap: () { /* DO SOMETHING */},
  child: Row(
    children: [
      SizedBox(height: 45.0, child: Image.asset(widget.iconPath)),
      Text(widget.title, style: const TextStyle(fontSize: 20.0)),
      Checkbox(
        onChanged: null,
        value: (selectedLanguage == widget.id) ? true : false,
      )
    ],
  ),
)

>Solution :

You can wrap your Checkbox widget inside an IgnorePointer

IgnorePointer(
      child: Checkbox(
        value: selectedLanguage == widget.id,
        onChanged: (v) {
          // This won't get called
        },
      ),
    )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading