withCreatedAt<T, E> method
This method is used to automatically track when a document was created. The field name is configurable through the Firestore API setup.
Adds a 'createdAt' timestamp field to the map.
Example:
Parameters:
- [createdAtFieldName] The field name under which to store the timestamp
Returns:
A new [Map] with the created timestamp added
final data = {'name': 'John'};
final result = data.withCreated(createdAtFieldName: 'createdAt');
Implementation
/// Adds a 'createdAt' timestamp field to the map.
///
/// Example:
/// ```dart
///
/// Parameters:
/// - [createdAtFieldName] The field name under which to store the timestamp
///
/// Returns:
/// A new [Map] with the created timestamp added
/// final data = {'name': 'John'};
/// final result = data.withCreated(createdAtFieldName: 'createdAt');
/// ```
Map<T, E> withCreatedAt<T, E>({required String createdAtFieldName}) =>
(this..[createdAtFieldName] = Timestamp.now()) as Map<T, E>;