build method

  1. @override
Future<EntityListSnapshot<T>> build({
  1. required String type,
  2. required String queryKey,
  3. required EntityDecoder<T> fromGraph,
  4. EntityEncoder<T>? toGraph,
  5. ListQuery query = const ListQuery(),
  6. ViewCompleteness completeness = ViewCompleteness.remote,
  7. bool enabled = true,
  8. bool subscribe = true,
})

Implementation

@override
Future<EntityListSnapshot<T>> build({
  required String type,
  required String queryKey,
  required EntityDecoder<T> fromGraph,
  EntityEncoder<T>? toGraph,
  ListQuery query = const ListQuery(),
  ViewCompleteness completeness = ViewCompleteness.remote,
  bool enabled = true,
  bool subscribe = true,
}) async {
  _disposed = false;
  _ready = false;
  final graph = ref.watch(entityGraphProvider);
  _viewRegistration?.dispose();
  _viewRegistration = graph.registerView(
    GraphViewDefinition(
      viewId: 'entity-list:${type.length}:$type:$queryKey',
      label: '$type list',
      kind: GraphViewKind.list,
      entityType: type,
      queryKey: queryKey,
    ),
  );
  if (subscribe) {
    ref.watch(entityChangeBridgeProvider<T>(type: type));
  }

  await _graphSubscription?.cancel();
  _graphSubscription = graph.changes.listen(_onGraphChange);
  ref.onDispose(() {
    _disposed = true;
    _viewRegistration?.dispose();
    unawaited(_graphSubscription?.cancel());
  });

  if (!enabled || completeness == ViewCompleteness.local) {
    _ready = true;
    return _buildSnapshot(graph);
  }
  if (completeness == ViewCompleteness.hybrid) {
    _ready = true;
    unawaited(_loadHybrid(graph));
    return _buildSnapshot(graph);
  }

  await _doFetch(graph);
  _ready = true;
  return _buildSnapshot(graph);
}