withUpdatedAt<T, E> method

Map<T, E> withUpdatedAt<T, E>({
  1. required String updatedAtFieldName,
})

This method is used to automatically track when a document was last updated. The field name is configurable through the Firestore API setup.

Adds an 'updatedAt' timestamp field to the map.

Example:


Parameters:
- [updatedAtFieldName] The field name under which to store the timestamp

Returns:
A new [Map] with the updated timestamp added
final data = {'name': 'John'};
final result = data.withUpdated(updatedAtFieldName: 'updatedAt');

Implementation

/// Adds an 'updatedAt' timestamp field to the map.
///
/// Example:
/// ```dart
///
/// Parameters:
/// - [updatedAtFieldName] The field name under which to store the timestamp
///
/// Returns:
/// A new [Map] with the updated timestamp added
/// final data = {'name': 'John'};
/// final result = data.withUpdated(updatedAtFieldName: 'updatedAt');
/// ```
Map<T, E> withUpdatedAt<T, E>({required String updatedAtFieldName}) =>
    (this..[updatedAtFieldName] = Timestamp.now()) as Map<T, E>;