You can use CalendarDatePicker
widget on showDialog. It provides onDateChanged
can be used to close the dialog and pass the selectedDate.
_datePicker() async {
_myDateTime = await showDialog(
context: context,
builder: (context) {
return LayoutBuilder(builder: (_, constraints) {
final width = constraints.maxWidth;
final height = constraints.maxHeight;
return Center(
child: Material(
// ok or cancel buttons arent needed for this case, else you can use AlertDialog for general purpose
child: SizedBox(
width: width * 0.8, // cant managed being expanded
child: CalendarDatePicker(
initialDate: DateTime.now(),
firstDate: DateTime.now(),
lastDate: DateTime(2100),
onDateChanged: (DateTime value) {
Navigator.of(context).pop(value);
},
),
),
),
);
});
},
);
debugPrint("selected date is $_myDateTime");
}