OnDisconnect class final
Writes the server applies to one location when this client's connection ends, from
DatabaseReference.onDisconnect.
Each Future completes when the server has registered the write. Only registered writes count: when the
connection is lost, the client also applies them locally, raising events after the .info/connected
false event, and then forgets them. Applying them overrides running transactions at, above or below
each location as a DatabaseReference.set there would (see DatabaseReference.runTransaction); a
transaction whose value was sent before the drop has failed with disconnected by then. Registrations
are never persisted; after a restart, register them again when FirebaseDatabase.onConnected turns
true.
A Future fails with permission-denied when the rules refuse the write, and with disconnected when the
connection dropped after the request was sent and before the server answered: the registration may not
exist then, so register again at the next connect. A request made while offline waits for the
connection; it is not failed by a timeout.
db.onConnected.listen((bool connected) async {
if (!connected) return;
final DatabaseReference status = db.ref('status/$uid');
await status.onDisconnect.set('offline');
await status.set('online');
});
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
cancel(
) → Future< void> -
Cancels every onDisconnect write registered at this location and below it. Throws an
ArgumentError under
.info, as set does. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
) → Future< void> -
On disconnect, removes the location's data: the same as
set(null). -
set(
Object? value, {Object? priority}) → Future< void> -
On disconnect, replaces the location's data with
value, and its priority withprioritywhen given. Values are validated at the call as inDatabaseReference.set. -
toString(
) → String -
A string representation of this object.
inherited
-
update(
Map< String, Object?> values) → Future<void> -
On disconnect, writes each entry of
valuesbelow the location, leaving other children alone. Keys may be multi-segment paths ('a/b'). A key that names the location itself ('','/'or any string of only slashes) throws an ArgumentError that names the key, and nothing is registered; use set to replace the location on disconnect, or remove to delete it.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited