Skip to content

Instantly share code, notes, and snippets.

@febritecno
Last active December 7, 2023 14:14
Show Gist options
  • Save febritecno/0b98ebeb93ec5e6eb7ce4a43f937e8a6 to your computer and use it in GitHub Desktop.
Save febritecno/0b98ebeb93ec5e6eb7ce4a43f937e8a6 to your computer and use it in GitHub Desktop.
Flutter methods
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