Reputation: 167
I'm trying to make a modal bottom sheet with ListTile
s that contain a Checkbox
as the leading widget. However, the Checkbox
will receive tap event instead of the ListTile
, now showing the ink ripple effect for the tile and making me implement two onTap
/onChanged
callbacks.
I have tried not implementing the Checkbox
's onChanged
callback and wrapping it around an AbsorbPointer
widget, however in these two cases the ListTile
would also not get the tap event.
return ListTile(
onTap: onTap,
title: Text("Show expired schedules"),
leading: Checkbox(value: snapshot.data, onChanged: (_) => onTap()),
);
I would like to somehow make the Checkbox
not tappable, but have the ListTile
still receive the tap event. Kind of like AbsorbPointer
, except skipping one Widget, not absorbing the tap event entirely.
Upvotes: 2
Views: 826
Reputation: 746
You can either use IgnorePointer
or AbsorbPointer
.
Try with below code snippet
IgnorePointer(
child: ElevatedButton(
onPressed: () {},
child: Text('Not clickable Button'),
),
);
Try with below code snippet
AbsorbPointer(
child: ElevatedButton(
onPressed: () {},
child: Text('Not clickable Button'),
),
);
Upvotes: 0
Reputation: 267544
You can do that using AbsorbPointer
too
return ListTile(
onTap: onTap,
title: Text("Show expired schedules"),
leading: AbsorbPointer(
absorbing: _condition, // bool value, true makes it absorb touch event on CheckBox still making ListTile tappable.
child: Checkbox(value: snapshot.data, onChanged: (_) => onTap()),
),
);
Upvotes: 0
Reputation: 103421
Wrap your Checkbox
widget inside IgnorePointer
widget and it should work:
return ListTile(
onTap: onTap,
title: Text("Show expired schedules"),
leading: IgnorePointer(child: Checkbox(value: snapshot.data, onChanged: (_) => onTap())),
);
Upvotes: 5