← Flutter Reference

What is Drift in Flutter?

Data & Connectivity · Intermediate

By Abdelrahman Saed — Senior Mobile Engineer. Last updated: 2026-08-10.

Drift is a reactive, type-safe SQLite ORM for Flutter and Dart. It uses code generation to create typed table definitions and query APIs, with built-in support for reactive streams that automatically rebuild the UI when database rows change.

How it works

Drift generates Dart classes from your schema definitions:

// Define tables
class Stories extends Table {
  TextColumn get id => text()();
  TextColumn get title => text()();
  IntColumn get position => integer()();
  BoolColumn get isCompleted => boolean().withDefault(const Constant(false));

  @override
  Set<Column> get primaryKey => {id};
}

// Define the database
@DriftDatabase(tables: [Stories])
class AppDatabase extends _$AppDatabase {
  AppDatabase() : super(_openConnection());

  // Reactive query — returns a Stream that rebuilds when data changes
  Stream<List<Story>> watchStories() {
    return (select(stories)..orderBy([(t) => OrderingTerm(expression: t.position)])).watch();
  }
}

The watch() method is the killer feature: it returns a Stream<List<Story>> that emits a new list whenever any story row changes. The UI rebuilds automatically — no manual invalidation, no event bus, no setState.

At iStoria, Drift is the local data layer that PowerSync syncs against. Every read of user progress, chapters, streaks, and levels comes from Drift. When PowerSync updates a row in the background, Drift's stream emits a new value and the UI rebuilds.

When to use it

Use Drift when:

  • You need structured local storage with type-safe queries.
  • You want reactive queries — the UI auto-updates when data changes.
  • You're building an offline-first app and need a typed SQLite layer.

Choose Hive or Isar instead when:

  • You need key-value storage, not relational queries.
  • You want NoSQL flexibility without a schema.
  • You want to avoid code generation.

Strengths

  • Type-safe queries — the compiler catches schema mismatches
  • Reactive streams — watch() auto-updates the UI when rows change
  • Code generation — schema changes produce updated types automatically
  • Migration support — versioned schema migrations with helpers
  • Pairs perfectly with PowerSync for offline-first sync

Tradeoffs

  • Code generation step — adds build time and a .g.dart file per table
  • Learning curve — DAOs, companions, and custom queries have their own API
  • SQLite limitations — no full-text search on iOS without extra setup, limited JSON support

Comparisons

Related articles

Related case studies

FAQ

Is Drift better than sqflite?

Drift builds on sqflite and adds type safety, reactive streams, code generation, and migration helpers. For any app with more than one table, Drift is the better choice — raw sqflite requires hand-written SQL strings and manual cache invalidation. See our Drift vs sqflite comparison.

Does Drift work with PowerSync?

Yes — PowerSync exposes its synced tables as Drift-compatible views. You define your Drift schema to match the PowerSync sync rules, and PowerSync populates the tables. Drift's reactive streams then auto-update the UI as PowerSync syncs changes.


Available for hire. Abdelrahman Saed is a Senior Mobile Engineer (Flutter) — open to full-time, fractional, contract, or advisory work. Hire me →

Book a 20-minute call · Download the CV (PDF) · See how I work