get method

Object? get(
  1. Object field, {
  2. ServerTimestampBehavior serverTimestamps = ServerTimestampBehavior.none,
})

The value of field, or null if the field or the document doesn't exist.

field is a String (dots separate nested fields, 'address.city') or a FieldPath (for a name that contains a dot). Throws an ArgumentError for an invalid path. serverTimestamps configures the value of a server timestamp that has not been set yet (ServerTimestampBehavior.none, which gives null, by default).

The value is the raw stored value: a converter is not applied. Cast it to the type you expect.

final String? city = snapshot.get('address.city') as String?;
final Object? population = snapshot['population']; // same as get
final DateTime? founded = (snapshot.get('founded') as Timestamp?)?.toDate();

Implementation

Object? get(
  Object field, {
  ServerTimestampBehavior serverTimestamps = ServerTimestampBehavior.none,
}) {
  final FieldPath fieldPath = _fieldPathOf('DocumentSnapshot.get', field);
  final _FieldValueOptions fieldValueOptions = _FieldValueOptions(
    serverTimestampBehavior: serverTimestamps,
  );
  return _getInternal(fieldPath.internalPath, fieldValueOptions);
}