sqflite-ffi-flutter

Configures sqflite_ffi as a shared ffi SQLite database factory across Flutter isolates.

3.0k|555|Updated May 22, 2017
One-click install
npx skills add https://github.com/tekartik/sqflite --skill sqflite-ffi-flutter-tekartik
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sqflite-ffi-flutter
Source: https://github.com/tekartik/sqflite/tree/main/packages_flutter/sqflite_ffi/skills/sqflite-ffi-flutter
Command: npx skills add https://github.com/tekartik/sqflite --skill sqflite-ffi-flutter-tekartik

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Flutter apps that need SQLite on desktop and mobile via the ffi implementation face manual factory setup, per-isolate database instances, and plugin registration pitfalls. This Skill explains how package:sqflite_ffi auto-registers sqfliteDatabaseFactoryFfi and shares one sqflite isolate across all Flutter isolates. ## Core Features & Use Cases - Automatic plugin registration: SqfliteFfiPlugin.registerWith() runs sqfliteFfiInit() and sets the global databaseFactory on Windows, Linux, macOS, Android, and iOS with no main() code. - Cross-isolate sharing: One sqflite isolate is shared between the main isolate, compute, and Isolate.run via IsolateNameServer, preserving singleInstance semantics and transaction ordering. - Package selection guidance: Clear criteria for choosing between sqflite, sqflite_common_ffi, sqflite_ffi, and sqflite_common_ffi_web, plus coexistence rules when both native and ffi plugins are present. - Use Case: A Flutter desktop app runs heavy inserts in a compute isolate while the main isolate holds an open transaction; with rollbackActiveTransactionOnOpen: false and the shared factory, both isolates write to the same database in order. ## Quick Start Add sqflite_ffi to my Flutter app's pubspec.yaml and show me how to open a database from both the main isolate and a compute isolate sharing one instance.

Frequently Asked Questions about sqflite-ffi-flutter

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use sqflite on Flutter desktop with sqflite_ffi?▼

Add sqflite_ffi to dependencies and import package:sqflite_ffi/sqflite_ffi.dart. The plugin auto-registers sqfliteDatabaseFactoryFfi as the global databaseFactory at startup, so openDatabase() works on Windows, Linux, and macOS with no main() setup code.

sqflite vs sqflite_common_ffi vs sqflite_ffi: which should I use?▼

Use sqflite for the native plugin on iOS, Android, and macOS. Use sqflite_common_ffi for pure Dart desktop apps and tests where you set databaseFactory yourself. Use sqflite_ffi for Flutter apps wanting ffi everywhere with automatic registration and one sqflite isolate shared across isolates.

How do I access the same sqflite database from a compute isolate?▼

Call sqfliteDatabaseFactoryFfi.openDatabase with rollbackActiveTransactionOnOpen: false inside the compute function. The factory locates the shared sqflite isolate through IsolateNameServer, so both isolates use the same single-instance database with ordered transactions.

Does sqflite_ffi work on Flutter web?▼

No, sqflite_ffi is a no-op on the web: SqfliteFfiPlugin.registerWith() does nothing and sqfliteDatabaseFactoryFfi returns the unsupported ffi factory. Use sqflite_common_ffi_web for web targets instead.

Why does openDatabase fail with 'databaseFactory not initialized' in a spawned isolate?▼

Plugin registration does not run automatically in hand-spawned isolates, so the global databaseFactory is unset. Call DartPluginRegistrant.ensureInitialized() from dart:ui before openDatabase(), or use sqfliteDatabaseFactoryFfi directly, which needs no registration.

What happens when both sqflite and sqflite_ffi plugins are in pubspec.yaml?▼

Both plugins register with databaseFactoryOrNull ??=, so whichever the generated registrant lists first wins, which is unreliable. Assign the factory explicitly in main(): databaseFactory = sqfliteDatabaseFactoryFfi for ffi, or databaseFactorySqflitePlugin for the native plugin.