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)
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)
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:
First add the dependency:
dependencies:
sqflite_common_ffi:
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());
}
Currently the sqflite only supports Android Ios and Mac.
Alternatively, you can either use Hive or sembast.
If you want to perform queries on the database I suggest you use sembast.
both the packages currently supports all the platform however if you are using sembast you have to include the package sembast_web for web support.
Packages:
Hive: https://pub.dev/packages/hive
Sembast: https://pub.dev/packages/sembast
Sembast_web: https://pub.dev/packages/sembast_web
As @alextk noted, you can use sqflite_common_ffi, to get the Windows support you desire. Depending on your requirements, a pure Dart option may be a better alternative though.
If you just want to store key/value pairs, Hive is probably the way to go, but if you want to store objects, ObjectBox is probably your best bet.
Here is a good article which contains a comparison of existing storage technologies for Flutter:
https://objectbox.io/flutter-databases-sqflite-hive-objectbox-and-moor/