idb_sqflite

Indexed DB for flutter on top of sqflite.

  • Supports both iOS and Android
  • Supports Flutter Web through idb_shim.
  • Supports Dart VM (Desktop) through idb_shim

Example

Simple notepad available here running on Flutter (iOS/Android/Web).

Getting Started

import 'package:idb_sqflite/idb_sqflite.dart';

Future main() async {
  // The sqflite base factory

  var factory = idbFactorySqflite;
  // define the store name
  const String storeName = "records";

  // open the database
  Database db = await factory.open("my_records.db", version: 1,
      onUpgradeNeeded: (VersionChangeEvent event) {
    Database db = event.database;
    // create the store
    db.createObjectStore(storeName, autoIncrement: true);
  });

  // put some data
  var txn = db.transaction(storeName, idbModeReadWrite);
  var store = txn.objectStore(storeName);
  var key = await store.put({"some": "data"});
  await txn.completed;

  // read some data
  txn = db.transaction(storeName, idbModeReadOnly);
  store = txn.objectStore(storeName);
  var value = await store.getObject(key);

  print(value);
  await txn.completed;
}

See idb_shim for API usage or more generally the W3C reference

Libraries

idb_client_sqflite
idb_sqflite

Dart

VM

dart:ffi
Foreign Function Interface for interoperability with the C programming language. [...]

Web

dart:html
HTML elements and other resources for web-based applications that need to interact with the browser and the DOM (Document Object Model). [...]
dart:js
Low-level support for interoperating with JavaScript. [...]
dart:js_util
Utility methods to efficiently manipulate typed JSInterop objects in cases where the name to call is not known at runtime. You should only use these methods when the same effect cannot be achieved with @JS annotations. These methods would be extension methods on JSObject if Dart supported extension methods.