Dev94
Dev94

Reputation: 877

Unable to create database using sqflite_common_ffi plugin for flutter desktop

I want to create database for flutter desktop application. I am using sqflite_common_ffi plugin for this purpose but the issue is it doesn't me to create database and giving some error on onCreate method call.

 // this opens the database (and creates it if it doesn't exist)
  _initDatabase() async {
    Directory documentsDirectory = await getApplicationDocumentsDirectory();
    String path = join(documentsDirectory.path, _databaseName);
    var databaseFactory = databaseFactoryFfi;
    print('DATABASE PATH: $path');
    Database db = await databaseFactory.openDatabase(
      path,
      options: OpenDatabaseOptions(
        version: 1,
        onCreate: (Database db, int version) async {
          await db.execute('''
          CREATE TABLE $table (
            $columnId INTEGER PRIMARY KEY,
            $columnName TEXT NOT NULL,
             $columnType TEXT NOT NULL,
               $columnStatus TEXT NOT NULL,
            $columnFlag INTEGER NOT NULL
          )
          ''');
          print('TABLE CREATED');
        },
      ),
    );
    print('DATABASE CREATED');

    return db;
  }

This my code for creating database. When i run the application it gives the following error:

Image

Anyone please help me out. Thanks

Upvotes: 0

Views: 1245

Answers (1)

Pratik Butani
Pratik Butani

Reputation: 62419

Have you checked these steps:

https://pub.dev/packages/sqflite_common_ffi#windows

Should work as is in debug mode (sqlite3.dll is bundled).

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

sqfliteFfiInit is provided as an implementation reference for loading the sqlite library. Please look at sqlite3 if you want to override the behavior.

Upvotes: 1

Related Questions