I am searching for a plugin or any solution that make SQLite work on flutter desktop windows app, i tried sqflite plugin and it work well with macOS desktop app but it doesn't support windows.
-
4Sqflite is not available on desktop but you can use [moor](https://pub.dev/packages/moor) which is very close to Sqflite – huextrat Feb 11 '20 at 13:55
-
did moor supports windows app ? – Nadim Gouia Feb 11 '20 at 13:57
-
1Yes sure, moor works on Android, iOS, macOS, Windows, Linux & Web (cf: documentation) – huextrat Feb 11 '20 at 13:59
-
I wrote an answer, please accept it for other people who need this kind of information – huextrat Feb 11 '20 at 14:04
6 Answers
I had exactly same problem and used https://pub.dev/packages/sqflite_common_ffi, it works like a charm

- 17,993
- 23
- 107
- 210
-
2Yes this is the correct method for using sqflite on windows, see link below for easy implementation https://github.com/tekartik/sqflite/blob/master/sqflite_common_ffi/doc/using_ffi_instead_of_sqflite.md – mister_cool_beans Mar 31 '22 at 07:02
Sqflite is not available on desktop but you can use moor which is very close to Sqflite, according to the documentation: moor works on Android, iOS, macOS, Windows, Linux & Web
I advise you to use it to have a real support on all platforms very easily.

- 402
- 3
- 11
-
am trying moor with windows but i cant get auto generated classes like _$AppDatabase is there any additional configuration ? – Nadim Gouia Feb 11 '20 at 15:45
You can try ObjectBox. https://github.com/objectbox/objectbox-dart
- Add dependencies to your project
- On windows, run bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-dart/main/install.sh)
- It will download objectbox.dll, put it to path your-project\build\windows\runner\Debug\ or \Release
- enjoy!

- 21
- 3
-
For sqlite, you can try https://pub.dev/packages/sqflite_common_ffi 1. download sqlite.dll from https://www.sqlite.org/download.html 2. put sqlite.dll to debug or release dirctory 3. enjoy! But the db file will be generated in the wrong directory. I suggest you use ObjectBox. – ruoyu_2021 Jan 13 '21 at 21:39
There is an issue about that you can follow here: https://github.com/tekartik/sqflite/issues/356
Windows plugin support is not stable yet but there is an experimental support for windows using ffi (and actually the moor_ffi implementation) here: https://github.com/tekartik/sqflite_more/tree/master/sqflite_ffi_test

- 5,713
- 21
- 34
-
i tried both sqflite and moor_ffi and no one of them work on windows – Nadim Gouia Feb 12 '20 at 16:26
-
Have you tried the following sample: https://github.com/tekartik/sqflite_more/tree/master/sqflite_test_app (note that you have to be on flutter master on windows) – alextk Feb 12 '20 at 17:09
SQFlite on Windows
Step - 1
Remember to Download Windows Binary Download SQLite DDL FIle
Path
Add the DLL File to this path
Code
class SQFLite {
Database? _database;
Future<Database> get database async {
if (_database != null) {
return _database!;
}
_database = await initWinDB();
return _database!;
}
Future<Database> initWinDB() async {
sqfliteFfiInit();
final databaseFactory = databaseFactoryFfi;
return await databaseFactory.openDatabase(
inMemoryDatabasePath,
options: OpenDatabaseOptions(
onCreate: _onCreate,
version: 1,
),
);
}
// based on what type of data you want to add your Table
Future<void> _onCreate(Database database, int version) async {
final db = database;
await db.execute(""" CREATE TABLE IF NOT EXISTS users(
id INTEGER PRIMARY KEY,
name TEXT,
email TEXT,
password INTEGER,
phoneNumber INTEGER
)
""");
}
}
Initialization
Either you can write this in the main function or if you are working on separate file You can add it inside initState()
void initState() {
super.initState();
WidgetsFlutterBinding.ensureInitialized();
helper.initWinDB();
}
Github Code

- 91
- 1
- 4