fluttercheckboxontap

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.

enter image description here

Here is my code:

InkWell(
  onTap: () { /* DO SOMETHING */},
  child: Row(
    children: [
      SizedBox( /* The flag icon */ ),
      Text( /* The language name */ ),
      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
            },
          ),
        )