Skip to content

[Testing] containsSemantics can't find semanticsLabel inside FormField #173838

@desmond206x

Description

@desmond206x

Steps to reproduce

Start the two example tests.
The first one failes, the second one is successfully.

Expected results

Both tests should work.

Actual results

The first test can't find the semantics from the semantics tree, because it is wrapped inside a FormField Widget.

It was working with Flutter 3.29.x, but is broken since Flutter 3.32.x.
Also broken with 3.35.1 and master channel.

Code sample

Example app
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(
      title: 'Flutter Demo',
      theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple)),
      home: Scaffold(
        body: Column(
          children: [
            Semantics(
              label: 'first parent semantics label',
              explicitChildNodes: true,
              child: FormField(
                builder: (field) => Semantics(label: 'failing child semantics label', child: Container(height: 40)),
              ),
            ),
            Semantics(
              label: 'second parent semantics label',
              explicitChildNodes: true,
              child: Semantics(label: 'successful child semantics label', child: Container(height: 40)),
            ),
          ],
        ),
      ),
    );
  }
}
Example test
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:semantics/main.dart';

void main() {
  testWidgets('semantics broken', (WidgetTester tester) async {
    await tester.pumpWidget(const MyApp());

    debugDumpSemanticsTree();

    expect(
      tester.semantics.simulatedAccessibilityTraversal(),
      containsOnce(containsSemantics(label: 'failing child semantics label')),
    );
  });

  testWidgets('semantics successfully', (WidgetTester tester) async {
    await tester.pumpWidget(const MyApp());

    debugDumpSemanticsTree();
    expect(
      tester.semantics.simulatedAccessibilityTraversal(),
      containsOnce(containsSemantics(label: 'successful child semantics label')),
    );
  });
}

Screenshots or Video

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[Paste your output here]

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)a: tests"flutter test", flutter_test, or one of our testsc: regressionIt was better in the past than it is nowf: material designflutter/packages/flutter/material repository.found in release: 3.32Found to occur in 3.32found in release: 3.33Found to occur in 3.33found in release: 3.35Found to occur in 3.35frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-accessibilityOwned by Framework Accessibility team (i.e. responsible for accessibility code in flutter/flutter)triaged-accessibilityTriaged by Framework Accessibility team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions