DataSnapshot class final

The data at a location at one moment, from an event, Query.get, Query.once or a transaction.

value holds plain Dart data: null, bool, int, double, String, List<Object?> or Map<String, Object?>, at every depth, with no converters. Read it with patterns:

final DataSnapshot snapshot = await db.ref('users/ada').get();
if (snapshot.value case {'name': String name, 'age': num age}) {
  print('$name is $age');
}

Numbers: an integral number reads as int, any other as double, the same on the VM and with dart2wasm; a 5.0 you wrote reads back as the int 5, also before the server answers. On dart2js an integral value is both int and double, so match numeric fields as num, never double. Integers beyond 2^53 stored in integer form are exact on the VM (up to 64 bits) but not on the web. A -0.0 stored by another client reads as the double -0.0.

Lists: a node whose keys are all integer-like, with largest key below twice the number of keys, reads as a List with null in the holes. The same location can therefore read as a Map after one change and a List after another; iterate children when the shape can vary.

Annotations

Properties

children → Iterable<DataSnapshot>
The direct children in the query's index order, built lazily, each with its own ref and priority. A snapshot made by child, or taken from children, has no query: its own children come in priority order then key order.
no setter
childrenCount → int
The number of direct children.
no setter
exists → bool
Whether the location holds data. A location with no data reads value as null.
no setter
hasChildren → bool
Whether the location has children (a leaf value or no data has none).
no setter
hashCode → int
The hash code for this object.
no setterinherited
key → String?
The last segment of ref's path, or null at the root.
no setter
priority → Object?
The priority of the location: null, a num or a String. Every snapshot has its own, child snapshots included.
no setter
ref → DatabaseReference
The location this data was read from. For the snapshot of a child event, the child's location.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
value → Object?
The data as plain Dart values (see the class documentation), or null when there is none.
no setter

Methods

child(String path) → DataSnapshot
The snapshot of the location at path below this one. path may have several segments ('a/b') and may name a list index ('0'). A missing child is a snapshot whose exists is false. Throws an ArgumentError when path has a key with forbidden characters.
hasChild(String path) → bool
Whether the location at path below this one holds data; path may have several segments. Throws an ArgumentError when path has a key with forbidden characters.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() → Object?
The data in export form: a node with a priority becomes a map with .value (for a leaf) or its children plus .priority. So jsonEncode(snapshot) works. Numbers, priorities included, follow the rule of value: the server's 1.0 exports as the int 1.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited