Skip to content
pubscout

stock

1.1.2, released 2 years ago by xmartlabs.com

Dart package for async data loading, caching, and combining local and network data sources.

WASM-ready
$ flutter pub add stock
Source repository

What it does

Stock manages data requests by coordinating remote fetchers and local sources of truth (like databases or memory caches). It prevents excessive calls to the network and disk cache by utilizing data streams, built-in caching layers, and safe error handling.

AI-written summary of version 1.1.2, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to coordinate and cache data from both a local database and a remote API.
  • You want to avoid flooding your network with duplicate simultaneous requests for the same resource.
  • You need a robust stream-based approach to handle loading, data, and error states cleanly in your UI.

Skip it when

  • You only need simple local key-value storage without network synchronization.
  • Your application architecture does not rely on repositories or caching layers.

Strengths

  • Combines local and network data sources seamlessly.
  • Catches errors and wraps them into stream responses instead of throwing unhandled exceptions.
  • Provides built-in memory caching via CachedSourceOfTruth for non-stream sources.

Weaknesses

  • Requires proper setup of custom fetchers, sources of truth, and potential mapping logic.
  • Does not replace a complete state management solution on its own.

Setup

Kind
Pure Dart
Effort
Medium
Code generation
No
Direct dependencies
3

Requires defining a Fetcher, a SourceOfTruth, and integrating with a local database or cache solution.

final stock = Stock<String, List<Tweet>>(
    fetcher: fetcher,
    sourceOfTruth: sourceOfTruth,
);

stock.stream('user_id', refresh: true).listen((response) {
  response.when(
    onLoading: (origin) => print('Loading...'),
    onData: (origin, data) => print('Data: $data'),
    onError: (origin, error, stacktrace) => print('Error: $error'),
  );
});

Alternatives

Packages that do the same job and could replace stock.

  • tostore

    Local data engine providing key-value, SQL/NoSQL tables, vector embeddings, and hybrid text search.

  • safe_local_storage

    Key-value storage library for Dart/Flutter that safely reads and writes local data.

  • king_cache

    File‑ and IndexedDB‑based cache for API responses and markdown content.

  • hive_local_storage

    A wrapper around hive_ce for easy local data storage and encryption.

Works with

Packages commonly used together with stock: ones it builds on, ones built on it, and its own family.