-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Use case
Please tell us the problem you are running into that led to you wanting
a new feature.
We have a vertical list of ExpansionTile's, and would like the ability to disable user interaction on the ExpansionTile, while simultaneously allowing it's children to still be clickable. In our case, each ExpansionTile contains a grouping of cells, and we want the ExpansionTile that contains the currently selected item to be locked open. All of the other ExpansionTile's in the list should be able to be expanded or collapsed; only the ExpansionTile with the currently selected item should be locked open. Currently, disabling toggling an ExpansionTile is not supported.
As an example, here's a screenshot of a list of ExpansionTile's ("Every Element", "The Media Page", "The Question Page", "The Form Page"):

In this example, if you had the content selected 'Address of your favorite store', then that group (ExpansionTile) should be locked open, since that's what you currently have selected. The other ExpansionTile's should be toggle-able.
Describe the alternative solutions you've considered. Is there a package
on pub.dev/flutter that already solves this?
- Initially, I tried using an
AbsorbPointerthat wrapped theExpansionTileto disallow it from being toggled. That worked, but also disabled clicking on the children of theExpansionTile. - I considered using the package https://pub.dev/packages/advance_expansion_tile, but it looks outdated and unmaintained. There don't appear to be any other equivalent packages on pub.dev.
- I considered copy-pasting the
ExpansionTileFlutter Widget code and editing it to support this use-case, but decided against it since that would essentially 'freeze' the code in our repo and prevent us from getting updates to this Widget that Flutter releases in the future. It also prevents others from benefitting from this change.
Proposal
The ExpansionTile class constructor should be updated to take another parameter that controls if user interaction is enabled or not (a bool, perhaps named locked). It should be pretty easy to save this bool in the ExpansionTile class, and then reference it to enable / disable user interaction in the onTap handler of the ListTile in the _ExpansionTileState class.
Note: I also considered if the ExpansionTile's trailing property should be affected by this change, but currently think it makes the most sense to leave it as-is. One option would be to disable it if the widget is locked. Another option would be to hide it entirely if the widget is locked. This would likely make sense for the majority of the cases where the trailing property is a disclosure icon, but in some cases it might be a different icon (or a different type of Widget entirely). Given this, I think it makes the most sense to leave the trailing property unaffected by this change, as consumers of the ExpansionTile class can control the behavior of the trailing property as needed.