5

In my Flutter app I'm using sqflite to talk to a local database. I need to peek into JSON data. The JSON1 extension would be ideal for this. However, I can't load the extension in a Flutter app to make it available in my queries since the documentation is for C, not Dart.

  • Should I compile in different architectures for iOS and Android?
  • Where should the compiled file(s) be placed? I assume it's not added as an asset.
  • How to access/load the C extension in my Flutter/Dart code?

Suggestions for other well supported local databases (document databases or databases that support JSON queries) for Flutter are also welcome. I looked into Couchbase Lite, but the plugins (Fluttercouch, couchbase-lite-flutter) are still under development.

3
  • Many sqlite instances enable json1 by default instead of using it as a loadable extension... Have you checked to see if that's the case with your toolchain?
    – Shawn
    Commented Nov 17, 2018 at 20:48
  • I'm getting 'no such function: json_extract', so I'm assuming the json1 extension is not enabled unfortunately. Commented Nov 17, 2018 at 21:12
  • With sqflite version 1.2.1, I'm able to load the json function.
    – HugoTai
    Commented Feb 19, 2020 at 11:44

1 Answer 1

2

By default, sqflite uses the OS-supplied version of SQLite, which may not have json1 enabled.

Instead, use sqflite_ffi, which would ship a copy of SQLite with your application. Any recent version would include json1 automatically.

The process is explained here: https://github.com/tekartik/sqflite/blob/master/sqflite_common_ffi/doc/using_ffi_instead_of_sqflite.md

The gist is:

  1. Add sqflite_common_ffi and sqlite3_flutter_libs dependencies (in addition to sqflite).
  2. Call sqfliteFfiInit() before opening the database sqflite in your app.

An added advantage is that the ffi version also has much better performance.

Not the answer you're looking for? Browse other questions tagged or ask your own question.