Skip to content
pubscout

riverpod_sqflite

0.4.8, released 2 weeks ago by an unverified publisher

Adapter to persist Riverpod provider state in a local SQLite database via sqflite.

WASM-readyUnverified publisher
$ flutter pub add riverpod_sqflite

What it does

It supplies a storage provider and a Persistable mix‑in that automatically reads from and writes to an SQLite DB for Riverpod AsyncNotifier state. The package handles caching and decoding of JSON data.

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

Use it when

  • You need offline persistence of Riverpod state without writing manual DB code
  • You prefer SQLite over key‑value stores for structured data

Skip it when

  • You require remote synchronization or cloud storage
  • You use a different state‑management solution
  • You need a NoSQL or secure storage solution

Strengths

  • Seamless integration with Riverpod’s AsyncNotifier
  • Automatic read/write and caching logic
  • Leverages the widely‑used sqflite plugin

Weaknesses

  • Tied exclusively to Riverpod; not usable with other state managers
  • Adds SQLite dependency and associated native setup
  • Limited to SQLite – cannot switch to other storage backends easily

Setup

Kind
Flutter widgets
Effort
Medium
Code generation
No
Direct dependencies
5

Add sqflite to pubspec, ensure Android/iOS permissions for file storage, call getDatabasesPath() to locate DB file

final storageProvider = FutureProvider<JsonSqFliteStorage>((ref) async => JsonSqFliteStorage.open(join(await getDatabasesPath(),'riverpod.db')));

class TodosNotifier extends AsyncNotifier<List<Todo>> {
  @override
  FutureOr<List<Todo>> build() async {
    await persist(
      ref.watch(storageProvider.future),
      key: 'todos',
      options: const StorageOptions(cacheTime: StorageCacheTime.unsafe_forever),
      encode: jsonEncode,
      decode: (json) => (jsonDecode(json) as List).map((e)=>Todo.fromJson(e as Map<String,Object?>)).toList(),
    ).future;
    return state.value ?? [];
  }
}

Works with

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