tryRemoveLocalId<T, E> method
This method is used to clean up local ID fields that were added for internal use.
Removes a local ID field from the map if specified conditions are met.
Example:
final data = {'name': 'John', '_id': '123'};
final result = data.tryRemoveLocalId(
idFieldName: '_id',
Parameters:
- [idFieldName] The field name of the ID to remove
- [tryRemoveLocalId] Whether to attempt removing the ID
Returns:
A new [Map] with the ID removed if conditions are met
tryRemoveLocalId: true,
);
Implementation
/// Removes a local ID field from the map if specified conditions are met.
///
/// Example:
/// ```dart
/// final data = {'name': 'John', '_id': '123'};
/// final result = data.tryRemoveLocalId(
/// idFieldName: '_id',
///
/// Parameters:
/// - [idFieldName] The field name of the ID to remove
/// - [tryRemoveLocalId] Whether to attempt removing the ID
///
/// Returns:
/// A new [Map] with the ID removed if conditions are met
/// tryRemoveLocalId: true,
/// );
/// ```
Map<T, E> tryRemoveLocalId<T, E>({
required String idFieldName,
required bool tryRemoveLocalId,
}) =>
tryRemoveLocalId && containsKey(idFieldName)
? (this..remove(idFieldName)) as Map<T, E>
: this as Map<T, E>;