What is the solution for using sqflite for both android and windows? #784
-
One of my flutter projects needs to be deployed on Android and Windows. The app needs to store a lot of relational data on local storage. The documentation says that it supports only Android and iOS while as support for desktop platforms is achieved through sqflite_common_ffi. So what do i need to do if i need support for both Android and Windows? Do i need to include both of those packages (sqflite and sqflite_common_ffi) or what? I am a bit familiar with SQFLite as i have previously used it in one of my projects but i haven't used the sqflite_common_ffi yet. Please suggest the procedure to achieve functionality on both platforms. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Sorry for the lack of documentation. Indeed you can add both. (it will use sqflite on iOS/Android and sqlite_common_ffi in Windows). The API is the same. You only need to provide the proper factory on start such as: import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:sqflite/sqflite.dart';
Future main() async {
if (Platform.isWindows || Platform.isLinux) {
// Initialize FFI and use it on Windows and linux
sqfliteFfiInit();
databaseFactory = databaseFactoryFfi;
}
// Use the default factory on iOS/Android
runApp(MyApp());
} As a a side note, don't rely don't More information here |
Beta Was this translation helpful? Give feedback.
-
Correct. Or user whatever local folder you want to save your database to (absolute or relative to your app or your current directory). By default getDatabasePaths returns a dummy local path on Windows. |
Beta Was this translation helpful? Give feedback.
Sorry for the lack of documentation. Indeed you can add both. (it will use sqflite on iOS/Android and sqlite_common_ffi in Windows). The API is the same. You only need to provide the proper factory on start such as:
As a a side note, don't rely don't
getDatabasesPath()
on Windows, usepath_provider
instead to find a proper database file location.