Reputation: 3
I have a sign up form which includes users to select their date of birth. Apparently everything works well on desktop web however iphone users who are below than 18.1.1 can open the datepicker but cant select a date. At first I thought it was a datepicker issue for iphone users so i use another datepicker that was working on a old project. But then, apparently the datepicker issue also happens to be affecting on certain android phones such as Samsung Galaxy S23 Ultra and Samsung Z Flip 3.Below is my code.
TextFormField(
controller: controller.dateController,
validator: (value) {
if (value!.isEmpty) {
return 'Please select your Date of Birth';
}
return null;
},
readOnly: true,
decoration: InputDecoration(
contentPadding: EdgeInsets.only(top:5),
labelText: 'Date of Birth',
labelStyle: ISCustomTextStyles.titleMediumOnPrimary
.copyWith(fontSize: getFontSize(18)),
enabledBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: ISAppTheme.lime800),
),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: ISAppTheme.lime800),
),
suffixIcon: Transform.scale(
scale: 0.6, // Shrink the icon size
child: ImageIcon(
AssetImage(ImageConstant.calendarIcon),
color: ISAppTheme.gray300, // Icon color
),
),
),
onTap: () => controller.selectDate(),
The below code is called in another file which is the controller
Future<void> selectDate() async {
if(defaultTargetPlatform != TargetPlatform.iOS){
DateTime? pickedDate = await showDatePicker(
context: Get.context!,
initialDate: DateTime.now(),
firstDate: DateTime(1900),
locale: Locale("en"),
lastDate: DateTime(DateTime.now().year, 12, 31),
initialEntryMode: DatePickerEntryMode.calendarOnly,
);
if (pickedDate != null) {
String formattedDate = DateFormat('dd-MM-yyyy').format(pickedDate);
dateController.text = formattedDate;
dateOfBirth.value = pickedDate;
}
}
else {
DateTime? pickedDate = await DatePicker.showSimpleDatePicker(
Get.context!,
initialDate: DateTime.now(),
firstDate: DateTime(1900),
lastDate: DateTime(DateTime.now().year, 12, 31),
dateFormat: "dd-MMMM-yyyy",
locale: DateTimePickerLocale.en_us,
looping: true,
);
if (pickedDate != null) {
String formattedDate = DateFormat('dd-MM-yyyy').format(pickedDate);
dateController.text = formattedDate;
dateOfBirth.value = pickedDate;
}
}
}
Upvotes: 0
Views: 40