date-picker icon indicating copy to clipboard operation
date-picker copied to clipboard

Fatal error: Unexpectedly found nil while unwrapping an Optional value

Open smhemel opened this issue 2 years ago • 5 comments

Describe the bug Date Picker is not showing up. Getting Fatal error when I call atePicker.present() with valid options on Xcode.

My code:

DatePicker.present({
        mode: 'date',
        date: new Date().toISOString(),
        max: this.getMaxDate(from),
        theme: 'light',
      })
      .then((dateData) => {
         console.log(dateData);
      })

Error in Xcode: CapacitorCommunityDatePicker/Parse.swift:20: Fatal error: Unexpectedly found nil while unwrapping an Optional value

Screenshot 2023-09-10 at 12 34 37 AM

smhemel avatar Sep 09 '23 18:09 smhemel

I'm getting this same issue, did you manage to find a solution @smhemel ? :)

DanielDarrenJones avatar Sep 19 '23 12:09 DanielDarrenJones

@DanielDarrenJones No, I didn't find any solution. But, I implemented a custom date-picker component using component instead of this plugin. Below, I have provided a screenshot. You can try it.

Screenshot 2024-05-14 234254

smhemel avatar Sep 22 '23 18:09 smhemel

We've faced the same error in our project recently. In our case we were passing the following data to the DatePicker:

let { value: newValue } = await DatePicker.present({
  mode, // "time"
  date: value || dateSuggestion || undefined, // 24-hour formatted time string
  timezone,
  format: dateFormat, // "HH:mm"
  is24h: true,
  ios: {
    timezone,
    format: dateFormat,
    style: 'wheels',
    mode,
  },
  android: {
    timezone,
    format: dateFormat,
    mode,
  },
});

Despite the fact we explicitly passed the is24h and format params the plugin used the device's platform built-in Date formatter (DateFormatter from the Foundation code) - so devices with the 12 hour locale tried to parse the 24-hour formatted time, which returned nil. The things became worse because there's a "must-have-a-value" operator used:

// client/node_modules/@capacitor-community/date-picker/ios/Plugin/Parse.swift
return formatter.date(from: date)!;
//                               ^--- here

MaxDonchenko avatar Mar 15 '24 21:03 MaxDonchenko

Same error. @smhemel any idea ?

Kamsou avatar May 14 '24 16:05 Kamsou

Same error. @smhemel any idea ?

@Kamsou I didn't find any solution. Also, I did R&D to find an alternative date-picker plugin for the capacitor, but I didn't. After that, I implemented a custom date-picker component using component instead of this plugin. Below, I have provided a screenshot. You can try the component.

Screenshot 2024-05-14 234254

smhemel avatar May 14 '24 17:05 smhemel