flutter_sqlite 1.0.1
flutter_sqlite: ^1.0.1 copied to clipboard
A cross-platform Flutter SQLite plugin using FFI with annotation-based API
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.1
Then run:
flutter pub get
🚀 Usage #
1. Define Your Models #
import 'package:flutter_sqlite/flutter_sqlite.dart';
@Table('users')
class User {
@PrimaryKey(autoIncrement: true)
int? id;
String name;
String email;
int age;
User({
this.id,
required this.name,
required this.email,
required this.age,
});
}
@Table('posts')
class Post {
@PrimaryKey(autoIncrement: true)
int? id;
String title;
String content;
int userId;
DateTime createdAt;
Post({
this.id,
required this.title,
required this.content,
required this.userId,
required this.createdAt,
});
}
2. Initialize Database #
final database = FlutterSqliteDatabase();
// Open database
await database.open('my_database.db');
// Register tables
await database.register<User>();
await database.register<Post>();
3. Perform Operations #
// Insert a user
final user = User(
name: 'John Doe',
email: 'john@example.com',
age: 30,
);
await database.insert(user);
// Insert a post
final post = Post(
title: 'Hello World',
content: 'This is my first post',
userId: 1,
createdAt: DateTime.now(),
);
await database.insert(post);
// Query all users
final users = await database.getAll<User>();
print(users.map((u) => u.name).toList());
// Query all posts
final posts = await database.getAll<Post>();
print(posts.map((p) => p.title).toList());
// Close database
await database.close();
License #
MIT License
Copyright (c) 2025 Mohamed Shaheen