load method

  1. @override
Future<DataProviderResult<T>> load(
  1. RouteDataContext context
)
override

Loads typed data for the given context.

Implementation

@override
Future<DataProviderResult<T>> load(RouteDataContext context) async {
  if (shouldThrowError) {
    throw StateError('Simulated database connection failure.');
  }

  if (simulatedLatency != null) {
    await Future<void>.delayed(simulatedLatency!);
  }

  final key =
      context.parameters[lookupParam] ??
      context.queryParameters[lookupParam] ??
      context.path;

  final record = _store[key];
  if (record == null) {
    return DataProviderResult<T>.notFound();
  }

  if (record.isGone || record.data == null) {
    return DataProviderResult<T>.gone(cacheTags: record.cacheTags);
  }

  return DataProviderResult<T>.found(
    record.data as T,
    lastModified: record.lastModified,
    etag: record.etag,
    cacheTags: record.cacheTags,
  );
}