Skip to content

What is the solution for using sqflite for both android and windows? #784

Answered by alextekartik
hulcon asked this question in Q&A
Discussion options

You must be logged in to vote

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 getDatabasesPath() on Windows, use path_provider instead to find a proper database file location.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@hulcon
Comment options

Answer selected by hulcon
Comment options

You must be logged in to vote
1 reply
@hulcon
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants