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
PageStorageKeys might benefit from a way to identify their primary client #10868
Customer Leafy ran into a confusing problem: ExpansionTiles were asserting in initState():
Error: type 'double' is not a subtype of type 'bool' of 'value'
...
#0 _ExpansionTileState._isExpanded= (package:flutter/src/material/expansion_tile.dart:81)
#1 _ExpansionTileState.initState (package:flutter/src/material/expansion_tile.dart:95)
#2 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3502)
...
The problem was that the ExpansionTile's were looking up their expanded/collapsed boolean with PageStorage, but only the enclosing PageView specified a PageStorageKey. PageView uses PageStorage to save its double scroll offset.
In this case it would have been preferable for the expansion tiles to not save their state.
Some possible ways to improve things:
ExpansionTiles don't save their state by default. The dartdoc for a default false keepExpansionState could cover the need for a PageStorageKey.
Scrollables include an inherited widget that only exists to stop the page storage key tree traversal. If a key wasn't found by the time this widget was reached, the traversal would short-circuit.
The second approach seems like it would result in most apps quietly getting the behavior they'd expect. It would complicate explaining how PageStorageKeys work a little.
I guess another option is that we add the type back in to the key somehow, though then you'd have all the panels stomping on each other which is no good.
I know this is old but just ran into same problem myself. For a flutter beginner it's difficult to know what the problem is from the reported error. The simple fix is to specify a PageStorageKey as the ExpansionTile key. Hope this save someone some time!
Hey I actually just ran into this problem in a slightly different way. I'm using ExpansionTiles in a TabBarView and each ExpansionTile has a number of SwitchListTiles. I added a PageStorageKey to my ExpansionTiles so the expanded state would be saved but started getting this error. The fix for me was to add a PageStorageKey to each SwitchListTile as well since they have their own boolean selected values which were probably confusing the scroll offset lookup. Just throwing this out there in case this happens to anyone else!
I know this is old but just ran into same problem myself. For a flutter beginner it's difficult to know what the problem is from the reported error. The simple fix is to specify a PageStorageKey as the ExpansionTile key. Hope this save someone some time!
new ExpansionTile(key: new PageStorageKey("any string"), ...
You are right that the error is rather unhelpful, but there seem to be similar errors whenever widgets expect cached properties but can't find them. If you have more than one ExpansionTile, however, I believe they will each need a unique key to avoid stepping on each other.
I know this is old but just ran into same problem myself. For a flutter beginner it's difficult to know what the problem is from the reported error. The simple fix is to specify a PageStorageKey as the ExpansionTile key. Hope this save someone some time!
Hi. I have the opposite behavior. I am using ExpansionTile in a ListView. The doc say to use PageStorageKey
/// This widget is typically used with [ListView] to create an
/// "expand / collapse" list entry. When used with scrolling widgets like
/// [ListView], a unique [PageStorageKey] must be specified to enable the
/// [ExpansionTile] to save and restore its expanded state when it is scrolled
/// in and out of view.
I used PageStorageKey("any string") to handle isuues with expantion tile throwing error when expanded in a listview or a drawer, and it worked perfectly for me. I know the implementation is different but thanks for the idea.
Activity
Hixie commentedon Jun 21, 2017
I guess another option is that we add the type back in to the key somehow, though then you'd have all the panels stomping on each other which is no good.
devantic commentedon Apr 26, 2018
I know this is old but just ran into same problem myself. For a flutter beginner it's difficult to know what the problem is from the reported error. The simple fix is to specify a
PageStorageKeyas theExpansionTilekey. Hope this save someone some time!kgain21 commentedon Nov 8, 2018
Hey I actually just ran into this problem in a slightly different way. I'm using
ExpansionTilesin aTabBarViewand eachExpansionTilehas a number ofSwitchListTiles. I added aPageStorageKeyto myExpansionTilesso the expanded state would be saved but started getting this error. The fix for me was to add aPageStorageKeyto eachSwitchListTileas well since they have their own boolean selected values which were probably confusing the scroll offset lookup. Just throwing this out there in case this happens to anyone else!psine commentedon Nov 21, 2018
You are right that the error is rather unhelpful, but there seem to be similar errors whenever widgets expect cached properties but can't find them. If you have more than one
ExpansionTile, however, I believe they will each need a unique key to avoid stepping on each other.volkangurol commentedon Jun 8, 2019
I used "Key" It didnt work in my project. Thank you for your answer
bsr203 commentedon Jul 28, 2019
Hi. I have the opposite behavior. I am using
ExpansionTilein aListView. The doc say to use PageStorageKeywhen I add PageStorageKey like,
I get error when expand. Even with one item. Is it safe to use without PageStorageKey if there are multiple items and list is scrolled? Thanks.
Edit: Looks like the error is from a child
TextEditwidget. For example,bennybat50 commentedon Jan 16, 2020
I used PageStorageKey("any string") to handle isuues with expantion tile throwing error when expanded in a listview or a drawer, and it worked perfectly for me. I know the implementation is different but thanks for the idea.