Skip to content

[shared_preferences] Handle Date type objects on iOS and macOS. #4230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

maciek-atmoapps-com
Copy link

iOS handle Date type in user preferences, but shared_preferences package not. If UserDefaults include Date type object, application will crash during reading preferences.
To resolve the problem Date type is covert into timestamp, and app not crash.

List which issues are fixed by this PR. You must list at least one issue. flutter/flutter#128948

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Plist format used to store user preferences may include Date type objects which cannot be serialized and causes crash during reading of user preferences. Date type object are changed into timestamps in order to fix serialization.
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@stuartmorgan-g
Copy link
Contributor

Thanks for the contribution, but dates are not currently a supported file type for shared_preferences, and adding one-way-only handling, only on one platform, is not how we would approach supporting dates if we were to add it. If you want date support in shared_preferences, please file an issue so that it can be prioritized and discussed; this needs an agreement on approach and API design before a PR.

@tarrinneal
Copy link
Contributor

I'd like to add a note here that this issue (the crashing) is being addressed with this pr #3794 with an allowList to prevent undesirable preferences from being sent to flutter.

@tarrinneal tarrinneal reopened this Jun 16, 2023
@tarrinneal tarrinneal closed this Jun 16, 2023
@maciek-atmoapps-com maciek-atmoapps-com changed the title [shared_preferences] Fixed shared preferences crash for Date type objects on iOS. [shared_preferences] Fixed shared preferences crash for Date type objects on iOS and macOS. Jun 20, 2023
@maciek-atmoapps-com maciek-atmoapps-com changed the title [shared_preferences] Fixed shared preferences crash for Date type objects on iOS and macOS. [shared_preferences] Handle Date type objects on iOS and macOS. Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants