diff --git a/packages/flutter/lib/src/material/time_picker.dart b/packages/flutter/lib/src/material/time_picker.dart index 98d8835751..747fcf0c51 100644 --- a/packages/flutter/lib/src/material/time_picker.dart +++ b/packages/flutter/lib/src/material/time_picker.dart @@ -560,6 +560,7 @@ class _DayPeriodControl extends StatelessWidget { onTap: Feedback.wrapForTap(() => _setAm(context), context), child: Semantics( selected: amSelected, + button: true, child: Center( child: Text( materialLocalizations.anteMeridiemAbbreviation, @@ -577,6 +578,7 @@ class _DayPeriodControl extends StatelessWidget { onTap: Feedback.wrapForTap(() => _setPm(context), context), child: Semantics( selected: pmSelected, + button: true, child: Center( child: Text( materialLocalizations.postMeridiemAbbreviation, @@ -1522,6 +1524,7 @@ class _HourTextField extends StatelessWidget { selectedTime: selectedTime, isHour: true, style: style, + semanticHintText: MaterialLocalizations.of(context).timePickerHourLabel, validator: validator, onSavedSubmitted: onSavedSubmitted, onChanged: onChanged, @@ -1549,6 +1552,7 @@ class _MinuteTextField extends StatelessWidget { selectedTime: selectedTime, isHour: false, style: style, + semanticHintText: MaterialLocalizations.of(context).timePickerMinuteLabel, validator: validator, onSavedSubmitted: onSavedSubmitted, ); @@ -1561,6 +1565,7 @@ class _HourMinuteTextField extends StatefulWidget { @required this.selectedTime, @required this.isHour, @required this.style, + @required this.semanticHintText, @required this.validator, @required this.onSavedSubmitted, this.onChanged, @@ -1569,6 +1574,7 @@ class _HourMinuteTextField extends StatefulWidget { final TimeOfDay selectedTime; final bool isHour; final TextStyle style; + final String semanticHintText; final FormFieldValidator validator; final ValueChanged onSavedSubmitted; final ValueChanged onChanged; @@ -1636,10 +1642,14 @@ class _HourMinuteTextFieldState extends State<_HourMinuteTextField> { ); } final Color unfocusedFillColor = timePickerTheme.hourMinuteColor ?? colorScheme.onSurface.withOpacity(0.12); + // If screen reader is in use, make the hint text say hours/minutes. + // Otherwise, remove the hint text when focused because the centered cursor + // appears odd above the hint text. + final String hintText = MediaQuery.of(context).accessibleNavigation + ? widget.semanticHintText + : (focusNode.hasFocus ? null : _formattedValue); inputDecoration = inputDecoration.copyWith( - // Remove the hint text when focused because the centered cursor appears - // odd above the hint text. - hintText: focusNode.hasFocus ? null : _formattedValue, + hintText: hintText, fillColor: focusNode.hasFocus ? Colors.transparent : inputDecorationTheme?.fillColor ?? unfocusedFillColor, ); diff --git a/packages/flutter/test/material/time_picker_test.dart b/packages/flutter/test/material/time_picker_test.dart index 7b8f195cda..23a08f13af 100644 --- a/packages/flutter/test/material/time_picker_test.dart +++ b/packages/flutter/test/material/time_picker_test.dart @@ -324,8 +324,22 @@ void _tests() { final SemanticsTester semantics = SemanticsTester(tester); await mediaQueryBoilerplate(tester, false); - expect(semantics, includesNodeWith(label: 'AM', actions: [SemanticsAction.tap])); - expect(semantics, includesNodeWith(label: 'PM', actions: [SemanticsAction.tap])); + expect( + semantics, + includesNodeWith( + label: 'AM', + actions: [SemanticsAction.tap], + flags: [SemanticsFlag.isButton, SemanticsFlag.isSelected, SemanticsFlag.isFocusable], + ), + ); + expect( + semantics, + includesNodeWith( + label: 'PM', + actions: [SemanticsAction.tap], + flags: [SemanticsFlag.isButton, SemanticsFlag.isFocusable], + ), + ); semantics.dispose(); }); @@ -349,6 +363,32 @@ void _tests() { semantics.dispose(); }); + testWidgets('provides semantics information for text fields', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + await mediaQueryBoilerplate(tester, true, entryMode: TimePickerEntryMode.input, accessibleNavigation: true); + + expect( + semantics, + includesNodeWith( + label: 'Hour', + value: '07', + actions: [SemanticsAction.tap], + flags: [SemanticsFlag.isTextField, SemanticsFlag.isMultiline], + ), + ); + expect( + semantics, + includesNodeWith( + label: 'Minute', + value: '00', + actions: [SemanticsAction.tap], + flags: [SemanticsFlag.isTextField, SemanticsFlag.isMultiline], + ), + ); + + semantics.dispose(); + }); + testWidgets('can increment and decrement hours', (WidgetTester tester) async { final SemanticsTester semantics = SemanticsTester(tester); @@ -840,6 +880,7 @@ Future mediaQueryBoilerplate( double textScaleFactor = 1.0, TimePickerEntryMode entryMode = TimePickerEntryMode.dial, String helpText, + bool accessibleNavigation = false, }) async { await tester.pumpWidget( Localizations( @@ -852,6 +893,7 @@ Future mediaQueryBoilerplate( data: MediaQueryData( alwaysUse24HourFormat: alwaysUse24HourFormat, textScaleFactor: textScaleFactor, + accessibleNavigation: accessibleNavigation, ), child: Material( child: Directionality(