flutter_datetime_picker icon indicating copy to clipboard operation
flutter_datetime_picker copied to clipboard

how to set localeType the same as system language

Open woopluz opened this issue 5 years ago • 2 comments

how to set localeType the same as system language

woopluz avatar Dec 01 '20 08:12 woopluz

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,
      ),
    );

RicardoRB avatar Dec 15 '20 20:12 RicardoRB

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)),
);

fa0311 avatar Dec 19 '23 18:12 fa0311