Last active
December 7, 2023 14:14
-
-
Save febritecno/0b98ebeb93ec5e6eb7ce4a43f937e8a6 to your computer and use it in GitHub Desktop.
Flutter methods
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
datePicker(context, data(result)) async { | |
DateTime currentDate = DateTime.now(); | |
DateTime? pickedDate = await showDatePicker( | |
context: context, | |
initialDate: currentDate, | |
firstDate: DateTime(2015, 8), | |
lastDate: DateTime(2101), | |
); | |
if (pickedDate != null) { | |
TimeOfDay currentTime = TimeOfDay.now(); | |
TimeOfDay? pickedTime = await showTimePicker( | |
context: context, | |
initialTime: currentTime, | |
); | |
if (pickedTime != null) { | |
DateTime selectedDateTime = DateTime( | |
pickedDate.year, | |
pickedDate.month, | |
pickedDate.day, | |
pickedTime.hour, | |
pickedTime.minute, | |
); | |
clog(selectedDateTime.toString()); | |
String formattedString = | |
DateFormat('yyyy-MM-dd HH:mm:ss').format(selectedDateTime); | |
data(formattedString); | |
} | |
} | |
} | |
//usage: | |
await datePicker(context,(result) { | |
print(result); | |
}) | |
//// 2023-12-06 00:00:00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment