parseFirestoreData method

dynamic parseFirestoreData(
  1. dynamic data
)

Parses Firestore-specific data types into standard Dart types.

  • data: The data to parse.

Returns the parsed data.

Implementation

dynamic parseFirestoreData(dynamic data) {
  if (data is Timestamp) {
    // Convert Firestore Timestamp to Dart DateTime
    return data.toDate();
  } else if (data is GeoPoint) {
    // Convert Firestore GeoPoint to a Map with latitude and longitude
    return {'latitude': data.latitude, 'longitude': data.longitude};
  } else if (data is DocumentReference) {
    // Convert DocumentReference to its path
    return data.path;
  } else if (data is Map<String, dynamic>) {
    // Recursively parse each item in the map
    return data.map((key, value) => MapEntry(key, parseFirestoreData(value)));
  } else if (data is List) {
    // Recursively parse each item in the list
    return data.map((item) => parseFirestoreData(item)).toList();
  } else {
    // Return the data as-is if it's a standard Dart type (e.g., String, int, bool)
    return data;
  }
}