2

I have an ExpansionTile widget and it contains some children, what I want is to prevent the ExpansionTile from rebuilding its children when I expand it.

Is there any basic method or will I have to do some trick?

farouk osama
  • 2,374
  • 2
  • 12
  • 30

2 Answers2

3

just make this maintainState value true like this:

ExpansionTile(
    maintainState: true,
    children: [
    ...
    ]
)
farouk osama
  • 2,374
  • 2
  • 12
  • 30
1

Sure try to use automaticKeepAlive it will keep your widget alive without building again

If you want to keep it without building as a constant , you can use const type

For automaticKeepAlive check : https://api.flutter.dev/flutter/widgets/AutomaticKeepAliveClientMixin-mixin.html

Here more like this q & a

https://stackoverflow.com/a/52543119/11989529

ElsayedDev
  • 601
  • 1
  • 8
  • 15
  • Unfortunately I tried to use AutomaticKeepAliveClientMixin and it didn't work :(, It must not work with the ExpansionTile , Do you have any other solution, thank you – farouk osama Oct 01 '20 at 07:23
  • Farouk can you share with me the code with automaticKeep ..? – ElsayedDev Oct 01 '20 at 07:57