FetchStrategy<Input, Output> class
abstract
Strategy interface for pluggable data-fetching pipelines.
Defines HOW a piece of data is fetched and returned. Injected into providers/services alongside other dependencies, making the pipeline selection a construction-time concern rather than runtime branching.
This is analogous to SyncStrategy for sync-enabled repositories — it is the swappable strategy that controls the fetch pipeline without the caller needing to know which pipeline runs.
Naming contract
Input is the request descriptor (e.g. UrlSpark, BarcodeSpark).
Output is the domain result type (e.g. Listing, BarcodeListing).
Implementations
A strategy implementation should do exactly one thing: given an Input,
produce an Output using a specific pipeline (scraper config, AI, cache,
etc.). It should NOT contain selection logic — selection belongs in a
StrategySelector or in the use case that picks the strategy.
Example implementations
ScraperFetchStrategy: uses aChannelConfig-backed scraper pipelineAiFetchStrategy: scrapes with WebView + AI parser for unknown sitesFallbackFetchStrategy: tries scraper first, falls back to AI on failure
Usage with use cases
class GetUrlListingUseCase extends StreamUseCase<UrlListing, UrlSpark> {
final ListingService _service;
final FetchStrategy<UrlSpark, Listing> _strategy;
GetUrlListingUseCase(this._service, this._strategy);
@override
Stream<UrlListing> execute(UrlSpark params, CancelToken? cancelToken) {
return _strategy.fetch(params, cancelToken: cancelToken)
.map((l) => l.changeToUrlListing(url: l.url!));
}
}
Usage with a selector
final strategy = await selector.select(spark);
final listing = await strategy.fetchOne(spark);
Constructors
Properties
Methods
-
canHandle(
Input input) → Future< bool> -
Whether this strategy can handle
input. -
fetch(
Input input, {CancelToken? cancelToken}) → Stream< Output> -
Fetch results as a stream for
input. -
fetchOne(
Input input, {CancelToken? cancelToken}) → Future< Output> -
Fetch a single result for
input. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited