Skip to content

Commit 1f55bfa

Browse files
authored
[material_ui] Fix ExpansionTile WidgetSpan semantics assertion (flutter#12765)
On Android, embedding an `ExpansionTile` in a `WidgetSpan` can trigger a sibling-configuration conflict assertion when semantics are enabled. Its live-region `Semantics` uses `AccessibilityFocusBlockType.blockNode` but can merge into the surrounding semantics tree. This makes the live region a semantics container, so `blockNode` applies to an explicit node. The regression test uses the simpler reproduction suggested in flutter#190639 and relies on the semantics handle managed by `testWidgets`. Fixes flutter#188298. This ports flutter#190639 to `packages/material_ui`. The earlier package PR, flutter#12383, was closed while contributions were paused. On October 2, I rebased this replacement onto current `main` (`10cde9a3b`) to refresh its stale CI configuration. The contribution itself is unchanged: the semantics fix, its regression test, and a pending changelog entry. There are no custom CI changes in this PR. I used AI to help with the fix and regression test. ## Pre-Review Checklist Local validation after the October 2 rebase, on macOS with the already-installed Flutter 3.47.5 / Dart 3.13.4: - Full `material_ui` suite: `flutter test --no-pub --concurrency=2` — 8,222 passed, 12 existing skips, no failures. - Full example suite: `flutter test --no-pub --concurrency=1` in `packages/material_ui/example` — 406 passed, two existing skips, no failures. - ExpansionTile file separately: 64 passed, one existing skip (also included in the full suite). - Defaults generator suite: `dart test` — 72 passed. - Full-package `flutter analyze --no-pub`: no issues. - Dart formatting and `git diff --check`: passed. - `dart run script/tool/bin/flutter_plugin_tools.dart validate --packages material_ui --check-for-missing-changes --base-branch upstream/main`: passed. I repeated the regression's fail-without-fix check on the rebased branch: removing `container: true` produces the original `!conflict` assertion; restoring it makes the test pass. The existing `flutter_goldens` harness skips golden-image comparisons; I did not change that behavior. These are local test results, not a claim that repository-wide CI has passed. GitHub automatically removed the `CICD` label after the October 2 push. Could a maintainer reapply it for the refreshed head so the repository presubmits can run? The release metadata uses `material_ui`'s batch-release convention: a pending changelog entry with `version: patch`. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent d0bf954 commit 1f55bfa

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎packages/material_ui/lib/src/expansion_tile.dart‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,9 @@ class _ExpansionTileState extends State<ExpansionTile> {
696696
return Semantics(
697697
// Live region used to announce state changes (e.g., "expanded" or "collapsed")
698698
// without taking focus.
699-
// blockNode prevents this node from being part of the focus traversal.
699+
// The container ensures the live region forms the node that blockNode
700+
// removes from focus traversal.
701+
container: true,
700702
label: semanticsHint,
701703
liveRegion: true,
702704
accessibilityFocusBlockType: AccessibilityFocusBlockType.blockNode,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
changelog: |
2+
- Fixes an Android semantics assertion when an `ExpansionTile` is embedded in a `WidgetSpan`.
3+
version: patch

‎packages/material_ui/test/expansion_tile_test.dart‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,6 +2230,31 @@ void main() {
22302230
);
22312231
});
22322232
group('Semantics tests for android platform', () {
2233+
// Regression test for https://github.com/flutter/flutter/issues/188298.
2234+
testWidgets('ExpansionTile supports being embedded in a WidgetSpan', (
2235+
WidgetTester tester,
2236+
) async {
2237+
await tester.pumpWidget(
2238+
const MaterialApp(
2239+
home: Scaffold(
2240+
body: Text.rich(
2241+
TextSpan(
2242+
children: <InlineSpan>[
2243+
WidgetSpan(
2244+
child: ExpansionTile(
2245+
title: Text('Header'),
2246+
children: <Widget>[Text('Details')],
2247+
),
2248+
),
2249+
],
2250+
),
2251+
),
2252+
),
2253+
),
2254+
);
2255+
expect(find.text('Header'), findsOneWidget);
2256+
}, variant: const TargetPlatformVariant(<TargetPlatform>{TargetPlatform.android}));
2257+
22332258
testWidgets('Semantics liveregion updates when expansion state changes', (
22342259
WidgetTester tester,
22352260
) async {

0 commit comments

Comments
 (0)