query<C extends Component> method
All elements of type C, in priority order, in constant time.
The type C must have been registered beforehand, unless strictMode
is false, in which case the registration happens on the first query.
Implementation
Iterable<C> query<C extends Component>() {
final cache = _queries?[C];
if (cache == null) {
if (strictMode) {
throw StateError(
'Cannot query unregistered type $C. This list is in strict mode, '
'which requires register<$C>() to be called before the first '
'query<$C>(), so that the query cache is built at a controlled '
'moment (typically in onLoad) instead of in the middle of a frame. '
'To register types lazily instead, create the list with '
'strictMode: false.',
);
}
register<C>();
return query<C>();
}
// The cached list itself is returned, but typed as an Iterable to prevent
// accidental modification of the cache from the outside.
return cache.data as Iterable<C>;
}