mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add locale in DatePickerThemeData (#148292)
*This PR changes the date picker were add locale in DatePickerThemeData* *List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.* Fixes #148202 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
This commit is contained in:
parent
3d4fd550c2
commit
df95cb2984
@ -241,6 +241,15 @@ Future<DateTime?> showDatePicker({
|
||||
locale: locale,
|
||||
child: dialog,
|
||||
);
|
||||
} else {
|
||||
final DatePickerThemeData datePickerTheme = DatePickerTheme.of(context);
|
||||
if (datePickerTheme.locale != null) {
|
||||
dialog = Localizations.override(
|
||||
context: context,
|
||||
locale: datePickerTheme.locale,
|
||||
child: dialog,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return showDialog<DateTime>(
|
||||
|
||||
@ -75,6 +75,7 @@ class DatePickerThemeData with Diagnosticable {
|
||||
this.inputDecorationTheme,
|
||||
this.cancelButtonStyle,
|
||||
this.confirmButtonStyle,
|
||||
this.locale,
|
||||
});
|
||||
|
||||
/// Overrides the default value of [Dialog.backgroundColor].
|
||||
@ -347,6 +348,10 @@ class DatePickerThemeData with Diagnosticable {
|
||||
/// Overrides the default style of the confirm (OK) button of a [DatePickerDialog].
|
||||
final ButtonStyle? confirmButtonStyle;
|
||||
|
||||
/// An optional [locale] argument can be used to set the locale for the date
|
||||
/// picker. It defaults to the ambient locale provided by [Localizations].
|
||||
final Locale? locale;
|
||||
|
||||
/// Creates a copy of this object with the given fields replaced with the
|
||||
/// new values.
|
||||
DatePickerThemeData copyWith({
|
||||
@ -387,6 +392,7 @@ class DatePickerThemeData with Diagnosticable {
|
||||
InputDecorationTheme? inputDecorationTheme,
|
||||
ButtonStyle? cancelButtonStyle,
|
||||
ButtonStyle? confirmButtonStyle,
|
||||
Locale? locale,
|
||||
}) {
|
||||
return DatePickerThemeData(
|
||||
backgroundColor: backgroundColor ?? this.backgroundColor,
|
||||
@ -426,6 +432,7 @@ class DatePickerThemeData with Diagnosticable {
|
||||
inputDecorationTheme: inputDecorationTheme ?? this.inputDecorationTheme,
|
||||
cancelButtonStyle: cancelButtonStyle ?? this.cancelButtonStyle,
|
||||
confirmButtonStyle: confirmButtonStyle ?? this.confirmButtonStyle,
|
||||
locale: locale ?? this.locale,
|
||||
);
|
||||
}
|
||||
|
||||
@ -472,6 +479,7 @@ class DatePickerThemeData with Diagnosticable {
|
||||
inputDecorationTheme: t < 0.5 ? a?.inputDecorationTheme : b?.inputDecorationTheme,
|
||||
cancelButtonStyle: ButtonStyle.lerp(a?.cancelButtonStyle, b?.cancelButtonStyle, t),
|
||||
confirmButtonStyle: ButtonStyle.lerp(a?.confirmButtonStyle, b?.confirmButtonStyle, t),
|
||||
locale: t < 0.5 ? a?.locale : b?.locale,
|
||||
);
|
||||
}
|
||||
|
||||
@ -524,6 +532,7 @@ class DatePickerThemeData with Diagnosticable {
|
||||
inputDecorationTheme,
|
||||
cancelButtonStyle,
|
||||
confirmButtonStyle,
|
||||
locale,
|
||||
]);
|
||||
|
||||
@override
|
||||
@ -568,7 +577,8 @@ class DatePickerThemeData with Diagnosticable {
|
||||
&& other.dividerColor == dividerColor
|
||||
&& other.inputDecorationTheme == inputDecorationTheme
|
||||
&& other.cancelButtonStyle == cancelButtonStyle
|
||||
&& other.confirmButtonStyle == confirmButtonStyle;
|
||||
&& other.confirmButtonStyle == confirmButtonStyle
|
||||
&& other.locale == locale;
|
||||
}
|
||||
|
||||
@override
|
||||
@ -611,6 +621,7 @@ class DatePickerThemeData with Diagnosticable {
|
||||
properties.add(DiagnosticsProperty<InputDecorationTheme>('inputDecorationTheme', inputDecorationTheme, defaultValue: null));
|
||||
properties.add(DiagnosticsProperty<ButtonStyle>('cancelButtonStyle', cancelButtonStyle, defaultValue: null));
|
||||
properties.add(DiagnosticsProperty<ButtonStyle>('confirmButtonStyle', confirmButtonStyle, defaultValue: null));
|
||||
properties.add(DiagnosticsProperty<Locale>('locale', locale, defaultValue: null));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -50,6 +50,7 @@ void main() {
|
||||
),
|
||||
cancelButtonStyle: ButtonStyle(foregroundColor: MaterialStatePropertyAll<Color>(Color(0xffffff6f))),
|
||||
confirmButtonStyle: ButtonStyle(foregroundColor: MaterialStatePropertyAll<Color>(Color(0xffffff7f))),
|
||||
locale: Locale('en'),
|
||||
);
|
||||
|
||||
Material findDialogMaterial(WidgetTester tester) {
|
||||
@ -145,6 +146,7 @@ void main() {
|
||||
expect(theme.inputDecorationTheme, null);
|
||||
expect(theme.cancelButtonStyle, null);
|
||||
expect(theme.confirmButtonStyle, null);
|
||||
expect(theme.locale, null);
|
||||
});
|
||||
|
||||
testWidgets('DatePickerTheme.defaults M3 defaults', (WidgetTester tester) async {
|
||||
@ -223,6 +225,7 @@ void main() {
|
||||
expect(m3.inputDecorationTheme, null);
|
||||
expect(m3.cancelButtonStyle.toString(), equalsIgnoringHashCodes(TextButton.styleFrom().toString()));
|
||||
expect(m3.confirmButtonStyle.toString(), equalsIgnoringHashCodes(TextButton.styleFrom().toString()));
|
||||
expect(m3.locale, null);
|
||||
});
|
||||
|
||||
testWidgets('DatePickerTheme.defaults M2 defaults', (WidgetTester tester) async {
|
||||
@ -293,6 +296,7 @@ void main() {
|
||||
expect(m2.inputDecorationTheme, null);
|
||||
expect(m2.cancelButtonStyle.toString(), equalsIgnoringHashCodes(TextButton.styleFrom().toString()));
|
||||
expect(m2.confirmButtonStyle.toString(), equalsIgnoringHashCodes(TextButton.styleFrom().toString()));
|
||||
expect(m2.locale, null);
|
||||
});
|
||||
|
||||
testWidgets('Default DatePickerThemeData debugFillProperties', (WidgetTester tester) async {
|
||||
@ -354,7 +358,8 @@ void main() {
|
||||
'dividerColor: Color(0xffffff4f)',
|
||||
'inputDecorationTheme: InputDecorationTheme#00000(fillColor: Color(0xffffff5f), border: UnderlineInputBorder())',
|
||||
'cancelButtonStyle: ButtonStyle#00000(foregroundColor: WidgetStatePropertyAll(Color(0xffffff6f)))',
|
||||
'confirmButtonStyle: ButtonStyle#00000(foregroundColor: WidgetStatePropertyAll(Color(0xffffff7f)))'
|
||||
'confirmButtonStyle: ButtonStyle#00000(foregroundColor: WidgetStatePropertyAll(Color(0xffffff7f)))',
|
||||
'locale: en',
|
||||
]));
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user