flutter_datetime_picker
flutter_datetime_picker copied to clipboard
how to set localeType the same as system language
how to set localeType the same as system language
Try this:
locale: LocaleType.values.firstWhere(
(element) =>
element.toString() ==
'LocaleType.${Localizations.localeOf(context).languageCode}',
orElse: () => LocaleType.en,
),
Example:
DatePicker.showDateTimePicker(
context,
showTitleActions: true,
minTime: DateTime.now(),
maxTime: DateTime.now().add(Duration(days: 7)),
onChanged: (date) {
print('change $date');
},
onConfirm: (date) {
print('confirm $date');
},
currentTime: DateTime.now(),
locale: LocaleType.values.firstWhere(
(element) =>
element.toString() ==
'LocaleType.${Localizations.localeOf(context).languageCode}',
orElse: () => LocaleType.en,
),
);
Try this:
locale: LocaleType.values.firstWhere( (element) => element.toString() == 'LocaleType.${Localizations.localeOf(context).languageCode}', orElse: () => LocaleType.en, ),
This did not work, so I created a Fork
dependencies:
flutter_datetime_picker_sharp:
git:
url: https://github.com/fa0311/flutter_datetime_picker_sharp
await DatePicker.showDateTimePicker(
context,
currentTime: DateTime.now(),
locale: LocaleType.fromLocale(Localizations.localeOf(context)),
);