1

I've run into a really weird error, and I can't wrap my head around it.

I do a query like this:

var currentSnapshot = await Firestore.instance
        .collection('station1')
        .orderBy("servertime", descending: true)
        .limit(1)
        .snapshots()
        .first;

To get the most recent document in some collection based on the server-timestamp that I have on each document. For some reason, this results in retrieving the newest documents only when debugging line by line. This could indicate that it has something to do with timing, as I'm introducing a lot more time when stepping through things.

The code is called every X seconds through the use of this:

Timer.periodic(Duration(seconds: 120), (Timer t) => updateMeasurements());

When I run without stepping through it with the debugger, it seems to only retrieve the correct value the first time, and when there are new documents added in the collection, it does not retrieve these.

Am I doing any obvious mistakes? Any ideas on what to try? All help appreciated!

1 Answer 1

3

It seems like this was related to having persistence activated for Firestore in Flutter. It might be related to me doing first for the stream.

I disabled persistence as follows:

Firestore.instance.settings(persistenceEnabled: false);

And now it consistently retrieves the most recent value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.