You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Programmatically open and close ExpansionTile Widget. #60387
I was building a Card which would be placed at the bottom of the screen, ExpansionTile is the child of this widget. When I click this card, the showModalBottomSheet() is called in OnExpansionChanged, however, I don't know how to close it. An open and close feature would be nice.
Reacted by Dieter Nuytemans, SugyoIn-LBSTech, Alexander, Thamarakshan Pilla, Eric, Cat coder, Vivek Swaminathan, Willy, ChiPhanTlm, Dan Syrstad and 13 more
Related to #7024
Currently we only have initiallyExpanded which does it initially and there is no way to close ExpansionTile afterwards programmatically #7024 (comment)
Reacted by Mojtaba T, LiangHuang, Luis Angel Iñiguez Hernández, Atageldi, Thomas Vervik, Grant Hutchison, Mark Saturno, Nhat Minh, Daigo / Dio, John Lee and 4 more
For those looking for a solution before this has been implemented in Flutter:
You can simply copy the code of ExpansionTile and make a few changes.
I suggest renaming ExpansionTile and _ExpansionTileState to something else so the names don't cause confusion.
Make the previous _ExpansionTileState public (because we'll need to use a GlobalKey)
Add the method below. This will toggle the animation and state of ExpansionTileState when the new setting is different from the current one and changes nothing otherwise.
Now simply initialise ExpansionTile with a key and keep a reference to that key wherever you are using the Widget. Then you can call key.currentState.setExpanded(bool newExpandedState) when needed. Or click here to see my implementation. Edit: view code here, this version has an openExpansion and closeExpansion method instead of the setExpanded above so keep that in mind.
The actual implementation in Flutter will probably differ though (as I don't believe they want to expose _ExpansionTileState).
Reacted by PeppeHope and Navin Kodag
Reacted by Tomekske, George Amgad, Onwa and Daigo / Dio
For those looking for a solution before this has been implemented in Flutter:
You can simply copy the code of ExpansionTile and make a few changes.
I suggest renaming ExpansionTile and _ExpansionTileState to something else so the names don't cause confusion.
Make the previous _ExpansionTileState public (because we'll need to use a GlobalKey)
Add the method below. This will toggle the animation and state of ExpansionTileState when the new setting is different from the current one and changes nothing otherwise.
Now simply initialise ExpansionTile with a key and keep a reference to that key wherever you are using the Widget. Then you can call key.currentState.setExpanded(bool newExpandedState) when needed. Or click here to see my implementation.
The actual implementation in Flutter will probably differ though (as I don't believe they want to expose _ExpansionTileState).
Hello! Your link is broken.. Could you update it? Thanks)
For those looking for a solution before this has been implemented in Flutter:
You can simply copy the code of ExpansionTile and make a few changes.
I suggest renaming ExpansionTile and _ExpansionTileState to something else so the names don't cause confusion.
Make the previous _ExpansionTileState public (because we'll need to use a GlobalKey)
Add the method below. This will toggle the animation and state of ExpansionTileState when the new setting is different from the current one and changes nothing otherwise.
Now simply initialise ExpansionTile with a key and keep a reference to that key wherever you are using the Widget. Then you can call key.currentState.setExpanded(bool newExpandedState) when needed. Or click here to see my implementation.
The actual implementation in Flutter will probably differ though (as I don't believe they want to expose _ExpansionTileState).
Hello! Your link is broken.. Could you update it? Thanks)
FWIW, it's far far more elegant to use ExpansionPanel which supports programmatically expanding and collapsing rather than changing keys to force an ExpansionTile to be rebuilt (which breaks the expansion/collapse animations).
Reacted by Dieter Nuytemans, Thamarakshan Pilla, Eric, Thomas and Muhemmad Asbah Riyas
remember restart your app for apply changes... its worked for me.
Editing code from external libraries (such as Flutter), is HIGHLY discouraged.
When Flutter releases updates you're likely to get merge conflicts and/or the update will trample your local changes. Instead, you should make your changes a PR against flutter/flutter (of course adding tests and making sure your code is bug-free).
Contributing to flutter has a little bit of a learning curve but it's really not bad. See the contributing guide.
Reacted by Jeroen Meijer (Jay) and Kiss-Budai Matyas
Lol guys you all should really stop doing this. Updates will trample and break your changes-don't get in the habit of editing external libraries. It's extremally brittle.
If you all promise to stop editing external libraries I'll make a PR against ExpansionTile to support programmatic control.
Reacted by chocobopie, Dayron , Satyajit Malugu, timtimtim123, modus-x, Lorenzo Hidalgo, Nhat Minh, mono — Masayuki Ono, Daniel Gah, Kiss-Budai Matyas and 2 more
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
TahaTesser commentedon Jun 29, 2020
Related to #7024
Currently we only have
initiallyExpandedwhich does it initially and there is no way to closeExpansionTileafterwards programmatically #7024 (comment)ritvij-saxena commentedon Jun 29, 2020
Should I be looking forward to this feature in the near future?
maksof-Hussain commentedon Aug 5, 2020
is there any way to close or open an ExpansionList in current version without loosing the animation?
Nuytemans-Dieter commentedon Aug 14, 2020
For those looking for a solution before this has been implemented in Flutter:
You can simply copy the code of ExpansionTile and make a few changes.
Now simply initialise ExpansionTile with a key and keep a reference to that key wherever you are using the Widget. Then you can call
key.currentState.setExpanded(bool newExpandedState)when needed.Or click here to see my implementation. Edit: view code here, this version has anopenExpansionandcloseExpansionmethod instead of thesetExpandedabove so keep that in mind.The actual implementation in Flutter will probably differ though (as I don't believe they want to expose _ExpansionTileState).
AtamyratBabayev commentedon Aug 21, 2020
Hello! Your link is broken.. Could you update it? Thanks)
Nuytemans-Dieter commentedon Aug 21, 2020
Woops, my bad. Fixed it.
caseycrogers commentedon May 3, 2021
FWIW, it's far far more elegant to use
ExpansionPanelwhich supports programmatically expanding and collapsing rather than changing keys to force anExpansionTileto be rebuilt (which breaks the expansion/collapse animations).mrtdeh commentedon Sep 27, 2021
its easy with this trick :
1- open expantion_tile.dart
2- in the state class and add this code :
and then you can use
initiallyExpandedproperty as your ownisExapndedand change it...!!and next :`
remember restart your app for apply changes...
its worked for me.
caseycrogers commentedon Sep 28, 2021
Editing code from external libraries (such as Flutter), is HIGHLY discouraged.
When Flutter releases updates you're likely to get merge conflicts and/or the update will trample your local changes. Instead, you should make your changes a PR against
flutter/flutter(of course adding tests and making sure your code is bug-free).Contributing to flutter has a little bit of a learning curve but it's really not bad. See the contributing guide.
4 remaining items
ChiPhanTlm commentedon Jun 10, 2022
I custom the method base on other answers
caseycrogers commentedon Jun 10, 2022
Lol guys you all should really stop doing this. Updates will trample and break your changes-don't get in the habit of editing external libraries. It's extremally brittle.
If you all promise to stop editing external libraries I'll make a PR against
ExpansionTileto support programmatic control.glaceon2000 commentedon Aug 30, 2022
It's been more than 2 years and nothing?
Nuytemans-Dieter commentedon Aug 30, 2022
Some PRs have been made but all have been closed. This comment in #95727 suggests a good approach though.
TreyThomas93 commentedon Sep 1, 2022
Solution: https://github.com/TreyThomas93/flutter-expansion-tile-demo
globaltop126 commentedon Oct 26, 2022
Hello @ritvij-saxena.
Did you solve this problem?
I got an issue like this.
I want your contact.
Thank you.
github-actions commentedon Apr 7, 2023
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.