Unverified Commit 18ccfe63 authored by Rémi Doreau's avatar Rémi Doreau Committed by GitHub

Feat(cupertino): [date_picker] Date order parameter (#84599)

parent 21a95f6b
......@@ -188,7 +188,7 @@ enum _PickerColumnType {
/// There are several modes of the date picker listed in [CupertinoDatePickerMode].
///
/// The class will display its children as consecutive columns. Its children
/// order is based on internationalization.
/// order is based on internationalization, or the [dateOrder] property if specified.
///
/// Example of the picker in date mode:
///
......@@ -245,6 +245,9 @@ class CupertinoDatePicker extends StatefulWidget {
/// positive integer factor of 60.
///
/// [use24hFormat] decides whether 24 hour format is used. Defaults to false.
///
/// [dateOrder] determines the order of the columns inside [CupertinoDatePicker] in date mode.
/// Defaults to the locale's default date format/order.
CupertinoDatePicker({
Key? key,
this.mode = CupertinoDatePickerMode.dateAndTime,
......@@ -256,6 +259,7 @@ class CupertinoDatePicker extends StatefulWidget {
this.maximumYear,
this.minuteInterval = 1,
this.use24hFormat = false,
this.dateOrder,
this.backgroundColor,
}) : initialDateTime = initialDateTime ?? DateTime.now(),
assert(mode != null),
......@@ -355,6 +359,10 @@ class CupertinoDatePicker extends StatefulWidget {
/// Whether to use 24 hour format. Defaults to false.
final bool use24hFormat;
/// Determines the order of the columns inside [CupertinoDatePicker] in date mode.
/// Defaults to the locale's default date format/order.
final DatePickerDateOrder? dateOrder;
/// Callback called when the selected date and/or time changes. If the new
/// selected [DateTime] is not valid, or is not in the [minimumDate] through
/// [maximumDate] range, this callback will not be called.
......@@ -378,7 +386,7 @@ class CupertinoDatePicker extends StatefulWidget {
case CupertinoDatePickerMode.dateAndTime:
return _CupertinoDatePickerDateTimeState();
case CupertinoDatePickerMode.date:
return _CupertinoDatePickerDateState();
return _CupertinoDatePickerDateState(dateOrder: dateOrder);
}
}
......@@ -1049,6 +1057,13 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
}
class _CupertinoDatePickerDateState extends State<CupertinoDatePicker> {
_CupertinoDatePickerDateState({
required this.dateOrder,
});
final DatePickerDateOrder? dateOrder;
late int textDirectionFactor;
late CupertinoLocalizations localizations;
......@@ -1331,7 +1346,10 @@ class _CupertinoDatePickerDateState extends State<CupertinoDatePicker> {
List<_ColumnBuilder> pickerBuilders = <_ColumnBuilder>[];
List<double> columnWidths = <double>[];
switch (localizations.datePickerDateOrder) {
final DatePickerDateOrder datePickerDateOrder =
dateOrder ?? localizations.datePickerDateOrder;
switch (datePickerDateOrder) {
case DatePickerDateOrder.mdy:
pickerBuilders = <_ColumnBuilder>[_buildMonthPicker, _buildDayPicker, _buildYearPicker];
columnWidths = <double>[
......
......@@ -1221,6 +1221,35 @@ void main() {
);
});
testWidgets('DatePicker displays the date in correct order', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
home: Center(
child: SizedBox(
height: 400.0,
width: 400.0,
child: CupertinoDatePicker(
dateOrder: DatePickerDateOrder.ydm,
mode: CupertinoDatePickerMode.date,
onDateTimeChanged: (DateTime newDate) {},
initialDateTime: DateTime(2018, 1, 14, 10, 30),
),
),
),
),
);
expect(
tester.getTopLeft(find.text('2018')).dx,
lessThan(tester.getTopLeft(find.text('14')).dx),
);
expect(
tester.getTopLeft(find.text('14')).dx,
lessThan(tester.getTopLeft(find.text('January')).dx),
);
});
testWidgets('DatePicker displays hours and minutes correctly in RTL', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment