Search code examples
dartffisqfliteflutter-desktopdart-ffi

Flutter-Desktop sqflite ffi throwing error on release mode


I am using sqflite ffi for my database on desktop windows. I setup everything like in the sample. The application is working on debug built but if I run the application on release mode I'm getting the error in sqfliteFfiInit(). How can I fix that?

Invalid argument(s): Failed to load dynamic library (126)
Future<void> init() async {
  try {
    sqfliteFfiInit();
    
  } catch (e) {
    print(e.toString());  
  }
  _databaseFactory = databaseFactoryFfi;

   String path = '${await _databaseFactory.getDatabasesPath()}\\myDB.db';
   _db = await _databaseFactory.openDatabase(path);

   final List<Map<String, dynamic>> result = await _db.query(
     'sqlite_master',
      where: 'name = ?',
      whereArgs: <String>['MyDB'],
    );

    if(result.isEmpty){
      await _db.execute('''
CREATE TABLE MyDB (
  id INTEGER PRIMARY KEY,
  name TEXT
)
''');
  }
}

Solution

  • The sqflite ffi github page says:

    "In release mode, add sqlite3.dll in same folder as your executable."