SunnyApp / flutter_contact

A flutter plugin for retrieving, creating, saving, and watching contacts on native devices
BSD 3-Clause "New" or "Revised" License
80 stars 62 forks source link

NumberFormatException while loading contact with wrong birthday date format #51

Closed kawoon-app closed 3 years ago

kawoon-app commented 3 years ago

Hello. We use your plugin in our app and recently faced with this issue. A few of our users told us that they get error while loading contact list. In our code we see PlatformException that points to NumberFormatException while parsing "6 июля 1983".

How to reproduce:

  1. Go to https://contacts.google.com
  2. For any contact set birthday like "6 июля 1983"
  3. Wait for contacts synced to android device
  4. Try load Contacts from flutter app
  5. Get NumberFormatException
ericmartineau commented 3 years ago

Dates are tough - because we don't control their input. I've made a couple of changes in 0.8.1 that should help:

1) Replaced DateComponents with FlexiDate - I changed the name because the behavior is slightly different. When the library encounters a parsing error, it will still produce an instance of FlexiDate, but it will be marked isValid==false and the values for month, day, and year will be null. The original unparsed value will be retained and will be passed back through the library.
2) For the FlexiDate library, there are two methods for improving parsing: 1) you can provide your own parser by setting FlexiDateParser.instance. Also, there is a DefaultFlexiDateParser.locale field which can be set appropriately to the user's locale. This will fix issues such as parsing date tokens in other languages (such as the one provided in this example). The underlying library used for the date parsing is the intl package.