orderByChild method
Orders by the value of the child at path (which may have several segments) of each child.
Children without it come first.
With no range and no limit the client asks the server for all the data at this location and
orders it here, as get and the on<Thing> streams do, so no .indexOn rule is needed. With
startAt, startAfter, endAt, endBefore, equalTo or a limit the query is sent as it
is. When the rules have no .indexOn for path, get fails with index-not-defined, while
a stream or once still works: the server sends all the data at this location, the client
filters it, and a warning naming the missing .indexOn goes to the logger, once per server
listen.
final Query adults = db.ref('users').orderByChild('age').startAt(18);
Implementation
Query orderByChild(String path) {
if (path == r'$key') {
throw ArgumentError(
r'orderByChild: "$key" is invalid. Use orderByKey() instead.',
);
} else if (path == r'$priority') {
throw ArgumentError(
r'orderByChild: "$priority" is invalid. Use orderByPriority() instead.',
);
} else if (path == r'$value') {
throw ArgumentError(
r'orderByChild: "$value" is invalid. Use orderByValue() instead.',
);
}
validatePathString('orderByChild', 'path', path);
_validateNoPreviousOrderByCall('orderByChild');
final Path parsedPath = Path(path);
if (parsedPath.isEmpty) {
throw ArgumentError(
'orderByChild: cannot pass in empty path. Use orderByValue() instead.',
);
}
final QueryParams params = spec.params.orderBy(PathIndex(parsedPath));
_validateQueryEndpoints(params);
return _with(params, ordered: true);
}