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.
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.
93Compare
Works with
Packages commonly used together with drift_flutter: ones it builds on, ones built on it, and its own family.
- path_providerdrift_flutter depends on itProvides Flutter APIs to locate common filesystem directories on Android, iOS, macOS, Linux and Windows.
- sqlite3drift_flutter depends on itLightweight and convenient SQLite bindings for Dart using dart:ffi
- driftdrift_flutter depends on itDrift is a reactive library to store relational data in Dart and Flutter applications.
- sqlite3_flutter_libsdrift_flutter depends on itObsolete package that once bundled native SQLite libraries for Flutter; now contains no code.
- sqlcipher_flutter_libsdrift_flutter depends on itObsolete package for sqlite3 version 2.x, update to version 3.x instead
- drift_devSame familyGenerates Dart database code from Drift table definitions as a dev‑dependency.
- sqlite3_webSame familyAsync SQLite access on the web via workers with automatic storage detection
- drift_sqfliteSame familyFlutter-only drift implementation using sqflite for SQLite storage.