Custom action about query in subcollection

Hello folks !

A programming question to achieve a custom function on Flutterflow.

My database is made up of a collection of users. The documents in this collection have the characteristics of the users and a sub-collection with their sports sessions. These sports sessions have a description and a date.

I would like to make a function that takes the reference of the user's document as an argument. This function must return the date of the user's next sports session (ie the closest to the current time).

Thank you very much for your help! I would very much like to understand how such a function works.