Created
September 10, 2020 05:14
-
-
Save DevKhalyd/0f710d0dddd25e50cf804bbfeddebc3a to your computer and use it in GitHub Desktop.
Flutter DatePicker with lenguage support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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