My app has user chats, with a chats collection and a chat_messages sub-collection. Chat messages have a timestamp. Chat messages are rendered in a ListView and then in a Stack.
I now want to show a date in-between messages whenever it's a "new day" - the typical UI behaviour known from e.g. Whatsapp or Signal.
I had the following ideas:
1. (Preferred) I could show the text conditionally based on a custom function output. The custom function would check if the message's timestamp is different from a specific pagestate; if different --> show the date, and update the page state to this message's date (so that the date is not rendered again above subsequent messages on the same day).
PROBLEM: As far as I can tell, I would nee a custom action to access a page state - because custom functions can NOT access it. But how would I trigger the action without a user interaction?
2. I could add a value to chat_messages Documents (could be boolean, new_date). But I find that repetitive; and I would have to handle it in the cloud, because if client-side, there is a reasonable risk that two subsequent messages get this value to be "true".
... But perhaps there is another approach for this simple feature?