Skip to content

Instantly share code, notes, and snippets.

@DevKhalyd
Created September 10, 2020 05:14
Show Gist options
  • Save DevKhalyd/0f710d0dddd25e50cf804bbfeddebc3a to your computer and use it in GitHub Desktop.
Save DevKhalyd/0f710d0dddd25e50cf804bbfeddebc3a to your computer and use it in GitHub Desktop.
Flutter DatePicker with lenguage support
Future<String> getDateByUser(BuildContext context) async {
/*Support lenguage
How to: https://stackoverflow.com/questions/61529343/how-to-change-language-of-show-date-picker-in-flutter
https://flutter.dev/docs/development/accessibility-and-localization/internationalization
*/
DateTime selectedDate = DateTime.now();
final DateTime picked = await showDatePicker(
context: context,
initialDate: selectedDate,
locale: const Locale("es", ""),
firstDate: DateTime(2020, 1),
lastDate: DateTime(2101));
if (picked != null && picked != selectedDate) {
String dateReadable =
picked.toString().substring(0, 10).replaceAll('-', '/');
return dateReadable;
} else
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment