Make time picker accessible (#13152)

* make time picker accessible

* use new CustomPaint a11y API

* flutter_localizations tests; use bigger distance delta

* fix am/pm control; selected values

* fix translations; remove @mustCallSuper in describeSemanticsConfiguration

* exclude AM/PM announcement from iOS as on iOS the label is read back automatically
This commit is contained in:
Yegor
2017-12-08 14:29:28 -08:00
committed by GitHub
parent 927a143d79
commit b80751cdc3
30 changed files with 837 additions and 209 deletions

View File

@@ -45,6 +45,8 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
'viewLicensesButtonLabel': r'الاطّلاع على التراخيص',
'anteMeridiemAbbreviation': r'ص',
'postMeridiemAbbreviation': r'م',
'timePickerHourModeAnnouncement': r'حدد ساعات',
'timePickerMinuteModeAnnouncement': r'حدد دقائق',
},
'de': const <String, String>{
'scriptCategory': r'English-like',
@@ -77,6 +79,8 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
'viewLicensesButtonLabel': r'LIZENZEN ANZEIGEN',
'anteMeridiemAbbreviation': r'VORM.',
'postMeridiemAbbreviation': r'NACHM.',
'timePickerHourModeAnnouncement': r'Stunde auswählen',
'timePickerMinuteModeAnnouncement': r'Minute auswählen',
},
'de_CH': const <String, String>{
'scriptCategory': r'English-like',
@@ -140,6 +144,8 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
'viewLicensesButtonLabel': r'VIEW LICENSES',
'anteMeridiemAbbreviation': r'AM',
'postMeridiemAbbreviation': r'PM',
'timePickerHourModeAnnouncement': r'Select hours',
'timePickerMinuteModeAnnouncement': r'Select minutes',
},
'en_AU': const <String, String>{
'scriptCategory': r'English-like',
@@ -389,6 +395,8 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
'viewLicensesButtonLabel': r'VER LICENCIAS',
'anteMeridiemAbbreviation': r'A.M.',
'postMeridiemAbbreviation': r'P.M.',
'timePickerHourModeAnnouncement': r'Seleccione Horas',
'timePickerMinuteModeAnnouncement': r'Seleccione Minutos',
},
'es_US': const <String, String>{
'scriptCategory': r'English-like',
@@ -426,6 +434,8 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
'viewLicensesButtonLabel': r'مشاهده مجوزها',
'anteMeridiemAbbreviation': r'ق.ظ.',
'postMeridiemAbbreviation': r'ب.ظ.',
'timePickerHourModeAnnouncement': r'ساعت ها را انتخاب کنید',
'timePickerMinuteModeAnnouncement': r'دقیقه را انتخاب کنید',
},
'fr': const <String, String>{
'scriptCategory': r'English-like',
@@ -458,6 +468,8 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
'viewLicensesButtonLabel': r'AFFICHER LES LICENCES',
'anteMeridiemAbbreviation': r'AM',
'postMeridiemAbbreviation': r'PM',
'timePickerHourModeAnnouncement': r'Sélectionnez les heures',
'timePickerMinuteModeAnnouncement': r'Sélectionnez les minutes',
},
'fr_CA': const <String, String>{
'scriptCategory': r'English-like',
@@ -526,6 +538,8 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
'viewLicensesButtonLabel': r'הצגת הרישיונות',
'anteMeridiemAbbreviation': r'AM',
'postMeridiemAbbreviation': r'PM',
'timePickerHourModeAnnouncement': r'בחר שעות',
'timePickerMinuteModeAnnouncement': r'בחר דקות',
},
'it': const <String, String>{
'scriptCategory': r'English-like',
@@ -557,6 +571,8 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
'viewLicensesButtonLabel': r'VISUALIZZA LICENZE',
'anteMeridiemAbbreviation': r'AM',
'postMeridiemAbbreviation': r'PM',
'timePickerHourModeAnnouncement': r'Seleziona ore',
'timePickerMinuteModeAnnouncement': r'Seleziona minuti',
},
'ja': const <String, String>{
'scriptCategory': r'dense',
@@ -588,6 +604,8 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
'viewLicensesButtonLabel': r'ライセンスを表示',
'anteMeridiemAbbreviation': r'AM',
'postMeridiemAbbreviation': r'PM',
'timePickerHourModeAnnouncement': r'時を選択',
'timePickerMinuteModeAnnouncement': r'分を選択',
},
'ps': const <String, String>{
'scriptCategory': r'tall',
@@ -616,6 +634,8 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
'pasteButtonLabel': r'پیټ کړئ',
'selectAllButtonLabel': r'غوره کړئ',
'viewLicensesButtonLabel': r'لیدلس وګورئ',
'timePickerHourModeAnnouncement': r'وختونه وټاکئ',
'timePickerMinuteModeAnnouncement': r'منې غوره کړئ',
},
'pt': const <String, String>{
'scriptCategory': r'English-like',
@@ -644,6 +664,8 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
'pasteButtonLabel': r'COLAR',
'selectAllButtonLabel': r'SELECIONAR TUDO',
'viewLicensesButtonLabel': r'VER LICENÇAS',
'timePickerHourModeAnnouncement': r'Selecione horários',
'timePickerMinuteModeAnnouncement': r'Selecione Minutos',
},
'pt_PT': const <String, String>{
'scriptCategory': r'English-like',
@@ -709,6 +731,8 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
'viewLicensesButtonLabel': r'ЛИЦЕНЗИИ',
'anteMeridiemAbbreviation': r'АМ',
'postMeridiemAbbreviation': r'PM',
'timePickerHourModeAnnouncement': r'ВЫБРАТЬ ЧАСЫ',
'timePickerMinuteModeAnnouncement': r'ВЫБРАТЬ МИНУТЫ',
},
'ur': const <String, String>{
'scriptCategory': r'tall',
@@ -740,6 +764,8 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
'viewLicensesButtonLabel': r'لائسنسز دیکھیں',
'anteMeridiemAbbreviation': r'AM',
'postMeridiemAbbreviation': r'PM',
'timePickerHourModeAnnouncement': r'گھنٹے منتخب کریں',
'timePickerMinuteModeAnnouncement': r'منٹ منتخب کریں',
},
'zh': const <String, String>{
'scriptCategory': r'dense',
@@ -771,6 +797,8 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
'previousMonthTooltip': r'上个月',
'anteMeridiemAbbreviation': r'上午',
'postMeridiemAbbreviation': r'下午',
'timePickerHourModeAnnouncement': r'选择小时',
'timePickerMinuteModeAnnouncement': r'选择分钟',
},
};

View File

@@ -31,5 +31,7 @@
"selectAllButtonLabel": "اختيار الكل",
"viewLicensesButtonLabel": "الاطّلاع على التراخيص",
"anteMeridiemAbbreviation": "ص",
"postMeridiemAbbreviation": "م"
"postMeridiemAbbreviation": "م",
"timePickerHourModeAnnouncement": "حدد ساعات",
"timePickerMinuteModeAnnouncement": "حدد دقائق"
}

View File

@@ -28,5 +28,7 @@
"selectAllButtonLabel": "ALLE AUSWÄHLEN",
"viewLicensesButtonLabel": "LIZENZEN ANZEIGEN",
"anteMeridiemAbbreviation": "VORM.",
"postMeridiemAbbreviation": "NACHM."
"postMeridiemAbbreviation": "NACHM.",
"timePickerHourModeAnnouncement": "Stunde auswählen",
"timePickerMinuteModeAnnouncement": "Minute auswählen"
}

View File

@@ -143,5 +143,15 @@
"postMeridiemAbbreviation": "PM",
"@postMeridiemAbbreviation": {
"description": "The abbreviation for post meridiem (after noon) shown in the time picker. Translations for this abbreviation will only be provided for locales that support it."
},
"timePickerHourModeAnnouncement": "Select hours",
"@timePickerHourModeAnnouncement": {
"description": "The audio announcement made when the time picker dialog is set to hour mode."
},
"timePickerMinuteModeAnnouncement": "Select minutes",
"@timePickerMinuteModeAnnouncement": {
"description": "The audio announcement made when the time picker dialog is set to minute mode."
}
}

View File

@@ -28,5 +28,7 @@
"selectAllButtonLabel": "SELECCIONAR TODO",
"viewLicensesButtonLabel": "VER LICENCIAS",
"anteMeridiemAbbreviation": "A.M.",
"postMeridiemAbbreviation": "P.M."
"postMeridiemAbbreviation": "P.M.",
"timePickerHourModeAnnouncement": "Seleccione Horas",
"timePickerMinuteModeAnnouncement": "Seleccione Minutos"
}

View File

@@ -27,5 +27,7 @@
"selectAllButtonLabel": "انتخاب همه",
"viewLicensesButtonLabel": "مشاهده مجوزها",
"anteMeridiemAbbreviation": "ق.ظ.",
"postMeridiemAbbreviation": "ب.ظ."
"postMeridiemAbbreviation": "ب.ظ.",
"timePickerHourModeAnnouncement": "ساعت ها را انتخاب کنید",
"timePickerMinuteModeAnnouncement": "دقیقه را انتخاب کنید"
}

View File

@@ -28,5 +28,7 @@
"selectAllButtonLabel": "TOUT SÉLECTIONNER",
"viewLicensesButtonLabel": "AFFICHER LES LICENCES",
"anteMeridiemAbbreviation": "AM",
"postMeridiemAbbreviation": "PM"
"postMeridiemAbbreviation": "PM",
"timePickerHourModeAnnouncement": "Sélectionnez les heures",
"timePickerMinuteModeAnnouncement": "Sélectionnez les minutes"
}

View File

@@ -29,5 +29,7 @@
"selectAllButtonLabel": "בחירת הכול",
"viewLicensesButtonLabel": "הצגת הרישיונות",
"anteMeridiemAbbreviation": "AM",
"postMeridiemAbbreviation": "PM"
"postMeridiemAbbreviation": "PM",
"timePickerHourModeAnnouncement": "בחר שעות",
"timePickerMinuteModeAnnouncement": "בחר דקות"
}

View File

@@ -27,5 +27,7 @@
"selectAllButtonLabel": "SELEZIONA TUTTO",
"viewLicensesButtonLabel": "VISUALIZZA LICENZE",
"anteMeridiemAbbreviation": "AM",
"postMeridiemAbbreviation": "PM"
"postMeridiemAbbreviation": "PM",
"timePickerHourModeAnnouncement": "Seleziona ore",
"timePickerMinuteModeAnnouncement": "Seleziona minuti"
}

View File

@@ -27,5 +27,7 @@
"selectAllButtonLabel": "すべて選択",
"viewLicensesButtonLabel": "ライセンスを表示",
"anteMeridiemAbbreviation": "AM",
"postMeridiemAbbreviation": "PM"
"postMeridiemAbbreviation": "PM",
"timePickerHourModeAnnouncement": "時を選択",
"timePickerMinuteModeAnnouncement": "分を選択"
}

View File

@@ -26,5 +26,7 @@
"okButtonLabel": "سمه ده",
"pasteButtonLabel": "پیټ کړئ",
"selectAllButtonLabel": "غوره کړئ",
"viewLicensesButtonLabel": "لیدلس وګورئ"
"viewLicensesButtonLabel": "لیدلس وګورئ",
"timePickerHourModeAnnouncement": "وختونه وټاکئ",
"timePickerMinuteModeAnnouncement": "منې غوره کړئ"
}

View File

@@ -26,5 +26,7 @@
"okButtonLabel": "OK",
"pasteButtonLabel": "COLAR",
"selectAllButtonLabel": "SELECIONAR TUDO",
"viewLicensesButtonLabel": "VER LICENÇAS"
"viewLicensesButtonLabel": "VER LICENÇAS",
"timePickerHourModeAnnouncement": "Selecione horários",
"timePickerMinuteModeAnnouncement": "Selecione Minutos"
}

View File

@@ -30,5 +30,7 @@
"selectAllButtonLabel": "ВЫБРАТЬ ВСЕ",
"viewLicensesButtonLabel": "ЛИЦЕНЗИИ",
"anteMeridiemAbbreviation": "АМ",
"postMeridiemAbbreviation": "PM"
"postMeridiemAbbreviation": "PM",
"timePickerHourModeAnnouncement": "ВЫБРАТЬ ЧАСЫ",
"timePickerMinuteModeAnnouncement": "ВЫБРАТЬ МИНУТЫ"
}

View File

@@ -27,5 +27,7 @@
"selectAllButtonLabel": "سبھی منتخب کریں",
"viewLicensesButtonLabel": "لائسنسز دیکھیں",
"anteMeridiemAbbreviation": "AM",
"postMeridiemAbbreviation": "PM"
"postMeridiemAbbreviation": "PM",
"timePickerHourModeAnnouncement": "گھنٹے منتخب کریں",
"timePickerMinuteModeAnnouncement": "منٹ منتخب کریں"
}

View File

@@ -27,5 +27,7 @@
"nextMonthTooltip": "下个月",
"previousMonthTooltip": "上个月",
"anteMeridiemAbbreviation": "上午",
"postMeridiemAbbreviation": "下午"
"postMeridiemAbbreviation": "下午",
"timePickerHourModeAnnouncement": "选择小时",
"timePickerMinuteModeAnnouncement": "选择分钟"
}

View File

@@ -316,6 +316,12 @@ class GlobalMaterialLocalizations implements MaterialLocalizations {
@override
String get postMeridiemAbbreviation => _nameToValue['postMeridiemAbbreviation'];
@override
String get timePickerHourModeAnnouncement => _nameToValue['timePickerHourModeAnnouncement'];
@override
String get timePickerMinuteModeAnnouncement => _nameToValue['timePickerMinuteModeAnnouncement'];
/// The [TimeOfDayFormat] corresponding to one of the following supported
/// patterns:
///

View File

@@ -140,57 +140,58 @@ void main() {
],
child: new MediaQuery(
data: new MediaQueryData(alwaysUse24HourFormat: alwaysUse24HourFormat),
child: new Directionality(
textDirection: TextDirection.ltr,
child: new Navigator(
onGenerateRoute: (RouteSettings settings) {
return new MaterialPageRoute<dynamic>(builder: (BuildContext context) {
showTimePicker(context: context, initialTime: const TimeOfDay(hour: 7, minute: 0));
return new Container();
});
},
child: new Material(
child: new Directionality(
textDirection: TextDirection.ltr,
child: new Navigator(
onGenerateRoute: (RouteSettings settings) {
return new MaterialPageRoute<dynamic>(builder: (BuildContext context) {
return new FlatButton(
onPressed: () {
showTimePicker(context: context, initialTime: const TimeOfDay(hour: 7, minute: 0));
},
child: const Text('X'),
);
});
},
),
),
),
),
),
);
// Pump once, because the dialog shows up asynchronously.
await tester.pump();
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
}
testWidgets('respects MediaQueryData.alwaysUse24HourFormat == false', (WidgetTester tester) async {
await mediaQueryBoilerplate(tester, false);
final CustomPaint dialPaint = tester.widget(find.descendant(
of: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_Dial'),
matching: find.byType(CustomPaint),
));
final CustomPaint dialPaint = tester.widget(find.byKey(const ValueKey<String>('time-picker-dial')));
final dynamic dialPainter = dialPaint.painter;
final List<TextPainter> primaryOuterLabels = dialPainter.primaryOuterLabels;
expect(primaryOuterLabels.map((TextPainter tp) => tp.text.text), labels12To11);
final List<dynamic> primaryOuterLabels = dialPainter.primaryOuterLabels;
expect(primaryOuterLabels.map<String>((dynamic tp) => tp.painter.text.text), labels12To11);
expect(dialPainter.primaryInnerLabels, null);
final List<TextPainter> secondaryOuterLabels = dialPainter.secondaryOuterLabels;
expect(secondaryOuterLabels.map((TextPainter tp) => tp.text.text), labels12To11);
final List<dynamic> secondaryOuterLabels = dialPainter.secondaryOuterLabels;
expect(secondaryOuterLabels.map<String>((dynamic tp) => tp.painter.text.text), labels12To11);
expect(dialPainter.secondaryInnerLabels, null);
});
testWidgets('respects MediaQueryData.alwaysUse24HourFormat == true', (WidgetTester tester) async {
await mediaQueryBoilerplate(tester, true);
final CustomPaint dialPaint = tester.widget(find.descendant(
of: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_Dial'),
matching: find.byType(CustomPaint),
));
final CustomPaint dialPaint = tester.widget(find.byKey(const ValueKey<String>('time-picker-dial')));
final dynamic dialPainter = dialPaint.painter;
final List<TextPainter> primaryOuterLabels = dialPainter.primaryOuterLabels;
expect(primaryOuterLabels.map((TextPainter tp) => tp.text.text), labels00To23);
final List<TextPainter> primaryInnerLabels = dialPainter.primaryInnerLabels;
expect(primaryInnerLabels.map((TextPainter tp) => tp.text.text), labels12To11TwoDigit);
final List<dynamic> primaryOuterLabels = dialPainter.primaryOuterLabels;
expect(primaryOuterLabels.map<String>((dynamic tp) => tp.painter.text.text), labels00To23);
final List<dynamic> primaryInnerLabels = dialPainter.primaryInnerLabels;
expect(primaryInnerLabels.map<String>((dynamic tp) => tp.painter.text.text), labels12To11TwoDigit);
final List<TextPainter> secondaryOuterLabels = dialPainter.secondaryOuterLabels;
expect(secondaryOuterLabels.map((TextPainter tp) => tp.text.text), labels00To23);
final List<TextPainter> secondaryInnerLabels = dialPainter.secondaryInnerLabels;
expect(secondaryInnerLabels.map((TextPainter tp) => tp.text.text), labels12To11TwoDigit);
final List<dynamic> secondaryOuterLabels = dialPainter.secondaryOuterLabels;
expect(secondaryOuterLabels.map<String>((dynamic tp) => tp.painter.text.text), labels00To23);
final List<dynamic> secondaryInnerLabels = dialPainter.secondaryInnerLabels;
expect(secondaryInnerLabels.map<String>((dynamic tp) => tp.painter.text.text), labels12To11TwoDigit);
});
}