Skip to content
pubscout

drift_flutter

0.3.1, released 4 months ago by simonbinder.eu

Provides a simple Flutter‑specific helper to open drift databases on all platforms.

WASM-ready
$ flutter pub add drift_flutter
Source repository

What it does

The package supplies a driftDatabase() function that returns a DatabaseConnection appropriate for the current platform. It handles file locations, web wasm loading, and optional isolate sharing for native platforms.

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

Use it when

  • You are already using drift and need a Flutter‑friendly way to open databases.
  • You want automatic handling of platform‑specific storage paths and optional isolate sharing.
  • You target multiple platforms (mobile, desktop, web) with a single API.

Skip it when

  • You do not use drift and need a generic SQLite wrapper.
  • You require a pure‑Dart solution without native plugins.
  • You prefer a different storage model (key‑value, NoSQL).

Strengths

  • Cross‑platform (mobile, desktop, web) support out of the box.
  • Built‑in isolate sharing for background work.
  • Simple API – just call driftDatabase(name).

Weaknesses

  • Web requires manually adding sqlite3.wasm and drift_worker.js files.
  • Tied to drift; not useful without it.
  • Adds extra dependencies (path_provider, sqlite3_flutter_libs).

Setup

Kind
Flutter widgets
Effort
Medium
Code generation
No
Direct dependencies
7

Add the compiled sqlite3.wasm and drift_worker.js to the web folder for web support. Ensure path_provider is available for native platforms. No build_runner needed.

import 'package:drift/drift.dart';
import 'package:drift_flutter/drift_flutter.dart';

@DriftDatabase(...)
class MyAppDatabase extends _$MyAppDatabase {
  MyAppDatabase(super.e);
  MyAppDatabase.defaults() : super(driftDatabase(name: 'app_db'));
}

Alternatives

Packages that do the same job and could replace drift_flutter.

  • sqflite_common

    Provides a generic SQLite API without drift integration, useful if you don't need drift's query builder.

Works with

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