[a11y-app] Fix Autocomplete semantics label (#175409)

## Description

This PR updates the autocomplete page of the A11y assessments app. It
creates a single semantics node for the text above the autocomplete and
the autocomplete.

## Related Issue

Fixes [[VPAT][A11y][a11y-app] fix a11y_assessment autocomplete to have
proper labels](https://github.com/flutter/flutter/issues/173002)

## Tests

Adds 1 test.
This commit is contained in:
Bruno Leroux 2025-09-23 10:00:24 +02:00 committed by GitHub
parent 3a19743487
commit d5cd65b4ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 16 deletions

View File

@ -55,22 +55,25 @@ class _MainWidgetState extends State<_MainWidget> {
title: Semantics(headingLevel: 1, child: Text('$pageTitle Demo')),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Type below to autocomplete the following possible results: $_kOptions.'),
Autocomplete<String>(
optionsBuilder: (TextEditingValue textEditingValue) {
if (textEditingValue.text == '') {
return const Iterable<String>.empty();
}
return _kOptions.where((String option) {
return option.contains(textEditingValue.text.toLowerCase());
});
},
fieldViewBuilder: _fieldViewBuilder,
),
],
child: Semantics(
container: true,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Type below to autocomplete the following possible results: $_kOptions.'),
Autocomplete<String>(
optionsBuilder: (TextEditingValue textEditingValue) {
if (textEditingValue.text == '') {
return const Iterable<String>.empty();
}
return _kOptions.where((String option) {
return option.contains(textEditingValue.text.toLowerCase());
});
},
fieldViewBuilder: _fieldViewBuilder,
),
],
),
),
),
);

View File

@ -4,6 +4,7 @@
import 'package:a11y_assessments/use_cases/auto_complete.dart';
import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter_test/flutter_test.dart';
import 'test_utils.dart';
@ -28,4 +29,19 @@ void main() {
await tester.pumpAndSettle();
expect(findHeadingLevelOnes, findsOne);
});
testWidgets('The text is used as semantics label for the text field', (
WidgetTester tester,
) async {
await pumpsUseCase(tester, AutoCompleteUseCase());
await tester.pumpAndSettle();
const List<String> kOptions = <String>['apple', 'banana', 'lemon'];
const String label = 'Fruit';
final String message =
'Type below to autocomplete the following possible results: $kOptions.\n$label';
final SemanticsNode node = tester.semantics.find(find.bySemanticsLabel(message));
expect(node.flagsCollection.isTextField, isTrue);
});
}