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 { ...@@ -188,7 +188,7 @@ enum _PickerColumnType {
/// There are several modes of the date picker listed in [CupertinoDatePickerMode]. /// There are several modes of the date picker listed in [CupertinoDatePickerMode].
/// ///
/// The class will display its children as consecutive columns. Its children /// 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: /// Example of the picker in date mode:
/// ///
...@@ -245,6 +245,9 @@ class CupertinoDatePicker extends StatefulWidget { ...@@ -245,6 +245,9 @@ class CupertinoDatePicker extends StatefulWidget {
/// positive integer factor of 60. /// positive integer factor of 60.
/// ///
/// [use24hFormat] decides whether 24 hour format is used. Defaults to false. /// [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({ CupertinoDatePicker({
Key? key, Key? key,
this.mode = CupertinoDatePickerMode.dateAndTime, this.mode = CupertinoDatePickerMode.dateAndTime,
...@@ -256,6 +259,7 @@ class CupertinoDatePicker extends StatefulWidget { ...@@ -256,6 +259,7 @@ class CupertinoDatePicker extends StatefulWidget {
this.maximumYear, this.maximumYear,
this.minuteInterval = 1, this.minuteInterval = 1,
this.use24hFormat = false, this.use24hFormat = false,
this.dateOrder,
this.backgroundColor, this.backgroundColor,
}) : initialDateTime = initialDateTime ?? DateTime.now(), }) : initialDateTime = initialDateTime ?? DateTime.now(),
assert(mode != null), assert(mode != null),
...@@ -355,6 +359,10 @@ class CupertinoDatePicker extends StatefulWidget { ...@@ -355,6 +359,10 @@ class CupertinoDatePicker extends StatefulWidget {
/// Whether to use 24 hour format. Defaults to false. /// Whether to use 24 hour format. Defaults to false.
final bool use24hFormat; 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 /// 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 /// selected [DateTime] is not valid, or is not in the [minimumDate] through
/// [maximumDate] range, this callback will not be called. /// [maximumDate] range, this callback will not be called.
...@@ -378,7 +386,7 @@ class CupertinoDatePicker extends StatefulWidget { ...@@ -378,7 +386,7 @@ class CupertinoDatePicker extends StatefulWidget {
case CupertinoDatePickerMode.dateAndTime: case CupertinoDatePickerMode.dateAndTime:
return _CupertinoDatePickerDateTimeState(); return _CupertinoDatePickerDateTimeState();
case CupertinoDatePickerMode.date: case CupertinoDatePickerMode.date:
return _CupertinoDatePickerDateState(); return _CupertinoDatePickerDateState(dateOrder: dateOrder);
} }
} }
...@@ -1049,6 +1057,13 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> { ...@@ -1049,6 +1057,13 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
} }
class _CupertinoDatePickerDateState extends State<CupertinoDatePicker> { class _CupertinoDatePickerDateState extends State<CupertinoDatePicker> {
_CupertinoDatePickerDateState({
required this.dateOrder,
});
final DatePickerDateOrder? dateOrder;
late int textDirectionFactor; late int textDirectionFactor;
late CupertinoLocalizations localizations; late CupertinoLocalizations localizations;
...@@ -1331,7 +1346,10 @@ class _CupertinoDatePickerDateState extends State<CupertinoDatePicker> { ...@@ -1331,7 +1346,10 @@ class _CupertinoDatePickerDateState extends State<CupertinoDatePicker> {
List<_ColumnBuilder> pickerBuilders = <_ColumnBuilder>[]; List<_ColumnBuilder> pickerBuilders = <_ColumnBuilder>[];
List<double> columnWidths = <double>[]; List<double> columnWidths = <double>[];
switch (localizations.datePickerDateOrder) { final DatePickerDateOrder datePickerDateOrder =
dateOrder ?? localizations.datePickerDateOrder;
switch (datePickerDateOrder) {
case DatePickerDateOrder.mdy: case DatePickerDateOrder.mdy:
pickerBuilders = <_ColumnBuilder>[_buildMonthPicker, _buildDayPicker, _buildYearPicker]; pickerBuilders = <_ColumnBuilder>[_buildMonthPicker, _buildDayPicker, _buildYearPicker];
columnWidths = <double>[ columnWidths = <double>[
......
...@@ -1221,6 +1221,35 @@ void main() { ...@@ -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 { testWidgets('DatePicker displays hours and minutes correctly in RTL', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
CupertinoApp( 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