Skip to content

ExpansionTile: Support Disabling User Input #135770

@praxder

Description

@praxder

Is there an existing issue for this?

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"):
CleanShot 2023-09-29 at 13 26 47

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?

  1. Initially, I tried using an AbsorbPointer that wrapped the ExpansionTile to disallow it from being toggled. That worked, but also disabled clicking on the children of the ExpansionTile.
  2. 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.
  3. I considered copy-pasting the ExpansionTile Flutter 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.team-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions