The behavior for Date objects stored in Firestore is going to change AND YOUR APP MAY BREAKsteemCreated with Sketch.

in #utopian-io6 years ago (edited)

featured.png

That's a catchy title to grab your attention. But you don't need to worry no more. The Firebase SDK already allows you to configure the behavior properly on all officially supported platforms. And with this pull request merged, you can now also configure Flutter properly to avoid problems.

Repository

https://github.com/flutter/plugins

New Features

Pull request: https://github.com/flutter/plugins/pull/765

Adding complete support for all Firestore settings. The need originated from the upcoming change of snapshot timestamps that are announced if timestampsInSnapshotsEnabled isn't set to true.

Firebase has already announced the change of datatype for the Firestore timestamp, which will likely be a source of error if not configured properly for applications that are using Cloud Firestore.

This is fixing the warnings that are announced when using the Cloud Firestore without the proper settings. As displayed below.

W/Firestore( 9705): (0.6.6-dev) [Firestore]: The behavior for java.util.Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK.
W/Firestore( 9705): To hide this warning and ensure your app does not break, you need to add the following code to your app before calling any other Cloud Firestore methods:
W/Firestore( 9705): 
W/Firestore( 9705): FirebaseFirestore firestore = FirebaseFirestore.getInstance();
W/Firestore( 9705): FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
W/Firestore( 9705):     .setTimestampsInSnapshotsEnabled(true)
W/Firestore( 9705):     .build();
W/Firestore( 9705): firestore.setFirestoreSettings(settings);
W/Firestore( 9705): 
W/Firestore( 9705): With this change, timestamps stored in Cloud Firestore will be read back as com.google.firebase.Timestamp objects instead of as system java.util.Date objects. So you will also need to update code expecting a java.util.Date to instead expect a Timestamp. For example:
W/Firestore( 9705): 
W/Firestore( 9705): // Old:
W/Firestore( 9705): java.util.Date date = snapshot.getDate("created_at");
W/Firestore( 9705): // New:
W/Firestore( 9705): Timestamp timestamp = snapshot.getTimestamp("created_at");
W/Firestore( 9705): java.util.Date date = timestamp.toDate();
W/Firestore( 9705): 
W/Firestore( 9705): Please audit all existing usages of java.util.Date when you enable the new behavior. In a future release, the behavior will be changed to the new behavior, so if you do not follow these steps, YOUR APP MAY BREAK.



The Firestore timestamps will provide a with a much higher accuracy of time, down to nanoseconds since the regular date objects with millisecond precision causes a truncation that can lead to problems in subsequent queries where the nano-second accuracy differs.

GitHub Account

https://github.com/DennisAlund

Sort:  

Hi there,

That's a great contribution on a well-known project. Hope to see you around more. :)


Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you for your review, @emrebeyler!

So far this week you've reviewed 3 contributions. Keep up the good work!

Can I have a question?
I found this tag utopian-io by chance.
What is this tag's main topic? How can I enjoy this tag's post?
I just wonder about it and looked your post..

Hi @dennisalund!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @dennisalund!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Congratulations @dennisalund! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You received more than 100 as payout for your posts. Your next target is to reach a total payout of 250

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

Be ready for the next contest!

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @dennisalund! You received a personal award!

1 Year on Steemit

Click here to view your Board of Honor

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @dennisalund! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!