Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit a570fd2

Browse files
authored
Date picker special labeling for currentDate with localization and te… (#116433)
* Date picker special labeling for currentDate with localization and tests. * Updated CalendarDatePicker semantics test * removed recursive import * changed labeling for current date to be less verbose
1 parent ef6ead4 commit a570fd2

File tree

86 files changed

+432
-81
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+432
-81
lines changed

packages/flutter/lib/src/material/calendar_date_picker.dart

+5-2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,10 @@ class _CalendarDatePickerState extends State<CalendarDatePicker> {
188188
_textDirection = Directionality.of(context);
189189
if (!_announcedInitialDate) {
190190
_announcedInitialDate = true;
191+
final bool isToday = DateUtils.isSameDay(widget.currentDate, _selectedDate);
192+
final String semanticLabelSuffix = isToday ? ', ${_localizations.currentDateLabel}' : '';
191193
SemanticsService.announce(
192-
_localizations.formatFullDate(_selectedDate),
194+
'${_localizations.formatFullDate(_selectedDate)}$semanticLabelSuffix',
193195
_textDirection,
194196
);
195197
}
@@ -968,6 +970,7 @@ class _DayPickerState extends State<_DayPicker> {
968970
(widget.selectableDayPredicate != null && !widget.selectableDayPredicate!(dayToBuild));
969971
final bool isSelectedDay = DateUtils.isSameDay(widget.selectedDate, dayToBuild);
970972
final bool isToday = DateUtils.isSameDay(widget.currentDate, dayToBuild);
973+
final String semanticLabelSuffix = isToday ? ', ${localizations.currentDateLabel}' : '';
971974

972975
BoxDecoration? decoration;
973976
Color dayColor = enabledDayColor;
@@ -1019,7 +1022,7 @@ class _DayPickerState extends State<_DayPicker> {
10191022
// day of month before the rest of the date, as they are looking
10201023
// for the day of month. To do that we prepend day of month to the
10211024
// formatted full date.
1022-
label: '${localizations.formatDecimal(day)}, ${localizations.formatFullDate(dayToBuild)}',
1025+
label: '${localizations.formatDecimal(day)}, ${localizations.formatFullDate(dayToBuild)}$semanticLabelSuffix',
10231026
selected: isSelectedDay,
10241027
excludeSemantics: true,
10251028
child: dayWidget,

packages/flutter/lib/src/material/date_picker.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -2348,7 +2348,8 @@ class _MonthItemState extends State<_MonthItem> {
23482348
// day of month before the rest of the date, as they are looking
23492349
// for the day of month. To do that we prepend day of month to the
23502350
// formatted full date.
2351-
String semanticLabel = '${localizations.formatDecimal(day)}, ${localizations.formatFullDate(dayToBuild)}';
2351+
final String semanticLabelSuffix = DateUtils.isSameDay(widget.currentDate, dayToBuild) ? ', ${localizations.currentDateLabel}' : '';
2352+
String semanticLabel = '${localizations.formatDecimal(day)}, ${localizations.formatFullDate(dayToBuild)}$semanticLabelSuffix';
23522353
if (isSelectedDayStart) {
23532354
semanticLabel = localizations.dateRangeStartDateSemanticLabel(semanticLabel);
23542355
} else if (isSelectedDayEnd) {

packages/flutter/lib/src/material/material_localizations.dart

+6
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ abstract class MaterialLocalizations {
160160
/// as a hint text in the text field.
161161
String get searchFieldLabel;
162162

163+
/// Label indicating that a given date is the current date.
164+
String get currentDateLabel;
165+
163166
/// The format used to lay out the time picker.
164167
///
165168
/// The documentation for [TimeOfDayFormat] enum values provides details on
@@ -1015,6 +1018,9 @@ class DefaultMaterialLocalizations implements MaterialLocalizations {
10151018
@override
10161019
String get searchFieldLabel => 'Search';
10171020

1021+
@override
1022+
String get currentDateLabel => 'Today';
1023+
10181024
@override
10191025
String aboutListTileTitle(String applicationName) => 'About $applicationName';
10201026

packages/flutter/test/material/calendar_date_picker_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ void main() {
697697
isFocusable: true,
698698
));
699699
expect(tester.getSemantics(find.text('3')), matchesSemantics(
700-
label: '3, Sunday, January 3, 2016',
700+
label: '3, Sunday, January 3, 2016, Today',
701701
hasTapAction: true,
702702
isFocusable: true,
703703
));

packages/flutter/test/material/date_picker_test.dart

+6
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,12 @@ void main() {
822822
label: 'SELECT DATE\nFri, Jan 15',
823823
));
824824

825+
expect(tester.getSemantics(find.text('3')), matchesSemantics(
826+
label: '3, Sunday, January 3, 2016, Today',
827+
hasTapAction: true,
828+
isFocusable: true,
829+
));
830+
825831
// Input mode toggle button
826832
expect(tester.getSemantics(switchToInputIcon), matchesSemantics(
827833
tooltip: 'Switch to input',

packages/flutter/test/material/date_range_picker_test.dart

+18
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,24 @@ void main() {
10851085
expect(tester.getBottomRight(find.byType(DateRangePickerDialog)), const Offset(390.0, 600.0));
10861086
});
10871087
});
1088+
1089+
group('Semantics', () {
1090+
testWidgets('calendar mode', (WidgetTester tester) async {
1091+
final SemanticsHandle semantics = tester.ensureSemantics();
1092+
currentDate = DateTime(2016, DateTime.january, 30);
1093+
addTearDown(semantics.dispose);
1094+
await preparePicker(tester, (Future<DateTimeRange?> range) async {
1095+
expect(
1096+
tester.getSemantics(find.text('30')),
1097+
matchesSemantics(
1098+
label: '30, Saturday, January 30, 2016, Today',
1099+
hasTapAction: true,
1100+
isFocusable: true,
1101+
),
1102+
);
1103+
});
1104+
});
1105+
});
10881106
}
10891107

10901108
class _RestorableDateRangePickerDialogTestWidget extends StatefulWidget {

packages/flutter/test/material/localizations_test.dart

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ void main() {
121121
expect(localizations.keyboardKeyScrollLock, isNotNull);
122122
expect(localizations.keyboardKeySelect, isNotNull);
123123
expect(localizations.keyboardKeySpace, isNotNull);
124+
expect(localizations.currentDateLabel, isNotNull);
124125

125126
expect(localizations.aboutListTileTitle('FOO'), isNotNull);
126127
expect(localizations.aboutListTileTitle('FOO'), contains('FOO'));

0 commit comments

Comments
 (0)