Search code examples
sqlitefluttererror-handlingflutter-windows

Sqlite with Flutter Desktop Windows?


the app is work with android but not work with desktop

[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation fou nd for method getDatabasesPath on channel com.tekartik.sqflite)


Solution

  • As pointed in a comment sqflite_common_ffi allows using sqflite API on Desktop. It is not implemented as a flutter plugin as it also works in a regular dart VM.

    You might read this to see how to use your existing sqflite code on desktop. But since it is always better to explain a little bit more than adding a link, here are the basic steps:

    Setup

    First add the dependency:

    dependencies:
      sqflite_common_ffi:
    

    Initialization

    Then initialize ffi before running your app:

    import 'package:sqflite_common_ffi/sqflite_ffi.dart';
    import 'package:sqflite/sqflite.dart';
    
    Future main() async {
      if (Platform.isWindows || Platform.isLinux) {
        // Initialize FFI
        sqfliteFfiInit();
        // Change the default factory
        databaseFactory = databaseFactoryFfi;
      }
      runApp(MyApp());
    }