I am trying to check the user's device OS and display the Cupertino date picker top iOS users, and Material date picker to android users. Below is my code
Future<void> _selectDate(BuildContext context) async {
DateTime? picked;
if (Platform.isIOS) {
showCupertinoModalPopup(
context: context,
builder: (context) {
return Theme(
data: ThemeData.dark(),
child: Container(
height: 300,
color: Color.fromARGB(255, 255, 255, 255),
child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.date,
initialDateTime: DateTime.now(),
onDateTimeChanged: (val) {
setState(() {
picked = val;
});
}),
), // This will change to light theme.
);
},
);
} else if (Platform.isAndroid) {
picked = await showDatePicker(
context: context,
initialDate: selectedDate,
firstDate: DateTime(2015, 8),
lastDate: DateTime(2101),
builder: (context, child) {
return Theme(
data: ThemeData.dark(), // This will change to light theme.
child: child!);
});
}
if (picked != null && picked != selectedDate)
setState(() {
selectedDate = picked!;
formattedSelectedDate = picked.toString();
});
}
My Android code is working fine. However I have the following issues in my iOS code.
- I can't close the popup
- This opens as a bottom sheet, but I prefer as a dialog box like in Android version.
How can I fix these issues?