setPriority method

Future<void>? setPriority(
  1. dynamic priority
)

Sets a priority for the data at this Firebase Database location.

Priorities can be used to provide a custom ordering for the children at a location (if no priorities are specified, the children are ordered by key).

You cannot set a priority on an empty location. For this reason set() should be used when setting initial data with a specific priority and setPriority() should be used when updating the priority of existing data.

Children are sorted based on this priority using the following rules:

Children with no priority come first. Children with a number as their priority come next. They are sorted numerically by priority (small to large). Children with a string as their priority come last. They are sorted lexicographically by priority. Whenever two children have the same priority (including no priority), they are sorted by key. Numeric keys come first (sorted numerically), followed by the remaining keys (sorted lexicographically).

Note that priorities are parsed and ordered as IEEE 754 double-precision floating-point numbers. Keys are always stored as strings and are treated as numbers only when they can be parsed as a 32-bit integer.

Implementation

Future<void> setPriority(dynamic priority) async {
  return _database._channel.invokeMethod<void>(
    'DatabaseReference#setPriority',
    <String, dynamic>{
      'app': _database.app?.name,
      'databaseURL': _database.databaseURL,
      'path': path,
      'priority': priority,
    },
  );
}