flutter_sqlite
flutter_sqlite
is a high-performance, cross-platform SQLite plugin for Flutter using Dart FFI and SQLite amalgamation.
It provides full offline database support for Android, iOS, Web, macOS, Windows, and Linux — without using platform channels or raw SQL.
This package is designed to be simple, fast, and developer-friendly, giving you clean and structured APIs for managing your database and models.
Features
- 🚀 High Performance — up to 5x faster than
sqflite
, powered by Dart FFI - 📦 Zero Platform Channels — direct C interop with SQLite amalgamation
- 🌐 Web Support — ships with
sqlite3.wasm
+ JavaScript loader for Flutter Web - 🛠️ Model‑Driven API — use type‑safe models with
toMap
/fromMap
- 🗂️ Automatic Table Creation — easily define your schema with static SQL in your models
- 🔄 Reactive Queries (Planned) — Stream support for live updates
- 🔒 Thread‑Safe Operations — designed for safety in concurrent use cases
- 📦 Zero External Dependencies — only requires
ffi
package
Installation
Add the package to your pubspec.yaml
:
dependencies:
flutter_sqlite: ^1.0.2
Then run:
flutter pub get
🚀 Usage
1. Define Your Models
import 'package:flutter_sqlite/flutter_sqlite.dart';
class User extends Serializable {
@PrimaryKey(autoIncrement: true)
int? id;
String name;
String email;
int age;
User({this.id, required this.name, required this.email, required this.age});
@override
Map<String, dynamic> toMap() {
return {
'id': id,
'name': name,
'email': email,
'age': age,
};
}
@override
User fromMap(Map<String, dynamic> map) {
return User(
id: map['id'],
name: map['name'] ?? '',
email: map['email'] ?? '',
age: map['age'] ?? 0,
);
}
@override
TableInfo getTableInfo() {
return TableInfo(
dartType: User,
tableName: 'users',
columns: [
ColumnInfo(
dartName: 'id',
columnName: 'id',
type: 'INTEGER',
isPrimaryKey: true,
autoIncrement: true,
),
ColumnInfo(
dartName: 'name',
columnName: 'name',
type: 'TEXT',
isPrimaryKey: false,
autoIncrement: false,
),
ColumnInfo(
dartName: 'email',
columnName: 'email',
type: 'TEXT',
isPrimaryKey: false,
autoIncrement: false,
),
ColumnInfo(
dartName: 'age',
columnName: 'age',
type: 'INTEGER',
isPrimaryKey: false,
autoIncrement: false,
),
],
primaryKeyColumn: 'id',
);
}
@override
String toString() => 'User(id: $id, name: $name, email: $email, age: $age)';
}
2. Perform Operations
await database.open('my_database.db');
// Register tables
await database.register<User>(() => User(name: '', email: '', age: 0));
database.insert(User(name: 'Mohamed Shaheen', email: 'shaheen.swe@gmail.com', age: 34));
List users = await database.getAll<User>();
License
MIT License
Copyright (c) 2025 Mohamed Shaheen