Repository navigation
Fix Expansible crash when PageStorage holds a non-bool value - #192195
auto-submit[bot] merged 11 commits into
Conversation
PageStorage is untyped and the same bucket slot can be written by other widgets, such as a Scrollable that saves a double offset. Expansible read that slot with a bool cast, which threw a type error when the stored value was not a bool. Read the value first and only use it when it is a bool, otherwise fall back to the controller's state. Fixes flutter#192184
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
Thanks for the PR. I don't think modifying the guards alone is the right solution. On a high level I don't think Expansible should just arbitrarily read bools from PageStorage.
My intuition is Expansible should only read from and write to PageStorage if there is a PageStorageKey associated with the Expansible itself (or if the key is on an ancestor like ExpansionTile.
What do you think?
| final bool initiallyExpanded = | ||
| PageStorage.maybeOf(context)?.readState(context) as bool? ?? widget.controller.isExpanded; | ||
| // PageStorage is untyped and the same slot can be written by other widgets, | ||
| // such as a Scrollable that saves a double. Only use the stored value if it |
There was a problem hiding this comment.
This fixes the crash in Expansible, but not potential crashes in the Scrollable.
ExpansibleState._toggleExpansion writes a bool to PageStorage. But ScrollPositionWithSingleContext.restoreScrollOffset reads the page storage value as a double, which can cause basically the same crash as this one but in the reverse direction. An easy way to repro this is to create an Expansible with a key and have its body contain a Scrollable:
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Tap the tile to crash')),
body: const ExpansionTile(
key: PageStorageKey<String>('my_tile'),
title: Text('Tap me to expand'),
children: <Widget>[
SingleChildScrollView(
child: Text('Scrollable content inside ExpansionTile'),
),
],
),
),
);
}
}
At minimum we should also fix this in this PR. (side note, _PagePosition.restoreScrollOffset does the same thing too).
|
@victorsanni Agreed, an unkeyed Gating on the key does not cover the keyed case though, since a
Does checking the parent's key work for you, or should |
An Expansible without a PageStorageKey of its own, or on its parent, ends up in the slot of some ancestor key and collides with other widgets there, such as a Scrollable. Skip PageStorage in that case. Also make ScrollPosition and _PagePosition ignore a stored value that is not a double, since a keyed Expansible can share a slot with a Scrollable inside it.
|
@victorsanni Pushed the changes.
|
victorsanni
left a comment
There was a problem hiding this comment.
Thanks for the updates.
This approach feels very brittle overall, it is very dependent on the shape of the widget tree. So if an ExpansionTile for example wraps its Expansible in another widget, it would break. Also it is naive, the Expansible doesn't care what its parent is.
Is it possible to have a unique identifier attached to readState and writeState to ensure we are only using Expansible keys?
Expansible shared its PageStorage slot with other widgets under the same PageStorageKeys, such as a Scrollable, so the two overwrote each other and crashed on read. Save the expansion state under an identifier of its own instead.
|
@victorsanni Pushed. |
|
Hi, please remember to re-request a review when you have made changes to your PRs, so it can re-enter my review queue. Else I don't see that your PR has been updated and can't leave a review. |
|
autosubmit label was removed for flutter/flutter/192195, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
Thanks @victorsanni and @Mairramer for the approvals! I see Google testing failed. I can't see the internal logs, so if you can share what failed, I'm happy to fix it on my side. |
|
@victorsanni Good news, Google testing passed on the re-run. Could you add the autosubmit label again when you have a moment? Thanks a lot for all the help on this one! |
Roll Flutter from 4249ccbc18a3 to 426be968b5eb (44 revisions) flutter/flutter@4249ccb...426be96 2026-10-14 [email protected] Allow color delta tolerance in in-memory fuzzy image comparator (flutter/flutter#193937) 2026-10-14 [email protected] [web] Drop stale composing range after text is replaced mid-composition (flutter/flutter#194096) 2026-10-14 [email protected] Roll Skia from 2a2bbea66844 to acde3755d2e2 (1 revision) (flutter/flutter#194376) 2026-10-14 [email protected] Roll Skia from 128c983b12de to 2a2bbea66844 (1 revision) (flutter/flutter#194371) 2026-10-14 [email protected] Roll Skia from 48a294ed4955 to 128c983b12de (3 revisions) (flutter/flutter#194353) 2026-10-14 [email protected] feat(flutter_tools): extract WebDebugConfig from DebuggingOptions (flutter/flutter#194312) 2026-10-14 [email protected] Roll Skia from ea6781c5b6d1 to 48a294ed4955 (2 revisions) (flutter/flutter#194349) 2026-10-14 [email protected] Include <vector> in Android proc_table.h. (flutter/flutter#194325) 2026-10-14 [email protected] Roll Dart SDK from 5933cb486b4a to 6b50116630d0 (28 revisions) (flutter/flutter#194341) 2026-10-14 [email protected] Move GLES3 instancing API entry points to FOR_EACH_IMPELLER_GLES3_PROC (flutter/flutter#194319) 2026-10-14 [email protected] feat(flutter_tools): extract AndroidGradleConfig and move toGradleConfig to AndroidBuildInfo (flutter/flutter#194016) 2026-10-14 [email protected] Roll Skia from ae297bec6012 to ea6781c5b6d1 (8 revisions) (flutter/flutter#194331) 2026-10-14 [email protected] [flutter_tools] Migrate gradle_errors and deferred_components_prebuild_validator away from globals (flutter/flutter#193649) 2026-10-14 [email protected] [Impeller] Cache GLES sampler configuration in RenderPassStateCache (flutter/flutter#193922) 2026-10-14 [email protected] Roll pub packages (flutter/flutter#194332) 2026-10-13 [email protected] [tool] Migrate RunCommand to modular dependency injection (flutter/flutter#190791) 2026-10-13 [email protected] Include `engine/src/flutter/.ci.yaml` in quarterly `goldctl` checklist (flutter/flutter#194316) 2026-10-13 [email protected] [flutter_tools] Remove the last AMD module system support (flutter/flutter#193607) 2026-10-13 [email protected] Roll Skia from 8b3394a60654 to ae297bec6012 (5 revisions) (flutter/flutter#194310) 2026-10-13 [email protected] [web] Remove the a11y placeholder only after the gesture ends (flutter/flutter#194109) 2026-10-13 [email protected] Upgrade goldctl to the latest version (flutter/flutter#193932) 2026-10-13 [email protected] [flutter_tools] Lazily initialize AndroidStudio validation and optimize candidate selection (flutter/flutter#191968) 2026-10-13 [email protected] [flutter_tools] Clean up outdated widget preview TODOs and refactor static state (flutter/flutter#189437) 2026-10-13 [email protected] Roll Skia from e5b5db6d0d6f to 8b3394a60654 (2 revisions) (flutter/flutter#194306) 2026-10-13 [email protected] Redistribute TESTOWNERS for Android team (flutter/flutter#193861) 2026-10-13 [email protected] feat(flutter_tools): introduce Test and Drive specification objects (flutter/flutter#194017) 2026-10-13 [email protected] [Impeller] Keep the aspect ratio when shrinking images to the max texture size (flutter/flutter#194010) 2026-10-13 [email protected] [flutter tool] preserve inherited `DASH__SUPPRESS_ANALYTICS=true` for sub-tools (flutter/flutter#194261) 2026-10-13 [email protected] Roll Packages from d8d9e97 to a1ed23c (9 revisions) (flutter/flutter#194302) 2026-10-13 [email protected] Use PE/COFF AOT snapshots for Windows x64 (flutter/flutter#187594) 2026-10-13 [email protected] Fix Expansible crash when PageStorage holds a non-bool value (flutter/flutter#192195) 2026-10-13 [email protected] Roll Skia from ffeccb3ca58a to e5b5db6d0d6f (1 revision) (flutter/flutter#194297) 2026-10-13 [email protected] Explain why initState() is too early to depend on an inherited widget (flutter/flutter#192727) 2026-10-13 [email protected] Refactor TestPlatformDispatcher (flutter/flutter#192747) 2026-10-13 [email protected] Roll Skia from 3de0984208ec to ffeccb3ca58a (2 revisions) (flutter/flutter#194291) 2026-10-13 [email protected] Roll Skia from 0580c2b780f6 to 3de0984208ec (2 revisions) (flutter/flutter#194281) 2026-10-13 [email protected] Roll Skia from f641d55e07a8 to 0580c2b780f6 (3 revisions) (flutter/flutter#194275) 2026-10-13 [email protected] Roll Skia from 0e5d8d1be81b to f641d55e07a8 (1 revision) (flutter/flutter#194266) 2026-10-13 [email protected] Scaffold view metrics overrides (flutter/flutter#192764) 2026-10-13 [email protected] [web] Add SemanticsRole.listBox and SemanticsRole.option (flutter/flutter#192971) 2026-10-13 [email protected] Pin mac_unopt to macOS 15 (flutter/flutter#194254) 2026-10-13 [email protected] Roll pub packages (flutter/flutter#194257) 2026-10-12 [email protected] Roll Skia from 17f6986c226c to 0e5d8d1be81b (4 revisions) (flutter/flutter#194249) 2026-10-12 [email protected] Make DisplayLists' use of DlPaint, SkPaint, and impeller::Paint agree on the default isAntiAlias (flutter/flutter#193939) If this roll has caused a breakage, revert this CL and set the roller ...
…#192195) ## Description `Expansible` reads and writes its expansion state in `PageStorage`. The slot it uses is picked from the `PageStorageKey`s above it in the tree. An `Expansible` with no key of its own lands in the slot of some ancestor key and shares it with other widgets, such as a `Scrollable` that saves a `double` there. Reading that value with `as bool?` threw: ``` type 'double' is not a subtype of type 'bool?' in type cast _ExpansibleState.initState (expansible.dart) ``` The same collision goes the other way. The `Expansible` writes a `bool` into that slot, and `ScrollPosition.restoreScrollOffset` then throws reading it `as double?`. Changes: - `Expansible` saves its state under an identifier of its own, built from the `PageStorageKey`s above it, so it never shares a slot with other widgets under the same keys. - `ScrollPosition.restoreScrollOffset` and `_PagePosition.restoreScrollOffset` only use the stored value if it is a `double`. ## Related issue Fixes flutter#192184 Thanks to @FabriceLeger for reporting it with the exact crash location. ## Tests Added to `expansible_test.dart`: a non-bool value in the slot, an unkeyed `Expansible` in a keyed `ListView` (the scroll offset is not overwritten), a keyed `Expansible` containing a `Scrollable` (both keep their state), and a key on the parent (state is kept). Added to `page_view_test.dart` and `scroll_position_test.dart`: a non-double value in the slot. Each fails without the fix and passes with it. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Mairramer <[email protected]> Co-authored-by: Victor Sanni <[email protected]>
Description
Expansiblereads and writes its expansion state inPageStorage. The slot it uses is picked from thePageStorageKeys above it in the tree. AnExpansiblewith no key of its own lands in the slot of some ancestor key and shares it with other widgets, such as aScrollablethat saves adoublethere. Reading that value withas bool?threw:The same collision goes the other way. The
Expansiblewrites aboolinto that slot, andScrollPosition.restoreScrollOffsetthen throws reading itas double?.Changes:
Expansiblesaves its state under an identifier of its own, built from thePageStorageKeys above it, so it never shares a slot with other widgets under the same keys.ScrollPosition.restoreScrollOffsetand_PagePosition.restoreScrollOffsetonly use the stored value if it is adouble.Related issue
Fixes #192184
Thanks to @FabriceLeger for reporting it with the exact crash location.
Tests
Added to
expansible_test.dart: a non-bool value in the slot, an unkeyedExpansiblein a keyedListView(the scroll offset is not overwritten), a keyedExpansiblecontaining aScrollable(both keep their state), and a key on the parent (state is kept). Added topage_view_test.dartandscroll_position_test.dart: a non-double value in the slot. Each fails without the fix and passes with it.Pre-launch Checklist