Skip to content
Nuvyntra Labs

Platform integration

Flutter / Dart

dart:ffi wrapper. Pair the Dart package with the host native library.

Overview

dart:ffi wrapper. Desktop needs the C ABI next to the app. iOS links Nuvexa.xcframework. Android ships libnuvexa.so in the APK.

1. Download

From NuvexaDB v1.0.6:

Host you are runningFlutter zipNative zipLibrary file
macOS Apple SiliconNuvexaDB-Flutter-osx-arm64.zipNuvexaDB-Native-osx-arm64.ziplibnuvexa.dylib
Linux x64NuvexaDB-Flutter-linux-x64.zipNuvexaDB-Native-linux-x64.ziplibnuvexa.so
Androidsame Dart package (nuvexadb-flutter-1.0.6.tgz inside any Flutter zip)use NuvexaDB-Android.zip / NuvexaDB-Native-android-arm64.zip for libnuvexa.solibnuvexa.so in jniLibs/arm64-v8a/
iOSsame Dart package`NuvexaDB-Native-iOS.zip`Nuvexa.xcframework

The Flutter zip contains nuvexadb-flutter-1.0.6.tgz (pubspec.yaml + lib/). The Dart sources do not change by RID; the native zip must match the device.

2. Empty project

flutter create acme_store
cd acme_store

3. Add the downloaded package

Unpack nuvexadb-flutter-1.0.6.tgz to a sibling folder. In pubspec.yaml:

dependencies:
  nuvexadb:
    path: ../nuvexadb-flutter

Desktop / tests:

export NUVEXA_NATIVE_LIB="/absolute/path/to/libnuvexa.dylib"

iOS: add Nuvexa.xcframework to the Xcode Runner target; the Dart library uses DynamicLibrary.process().

Android: place libnuvexa.so at android/app/src/main/jniLibs/arm64-v8a/libnuvexa.so (or consume the published AAR). The loader then opens libnuvexa.so.

flutter pub get

4. Create, open, close

import 'package:nuvexadb/nuvexadb.dart';

final path = 'app.nvx';
final db = NuvexaDatabase.create(path, key: key);
// ...
db.close();

if (NuvexaDatabase.isEncrypted(path) && key == null) {
  throw StateError('Encrypted .nvx — pass key');
}
final opened = NuvexaDatabase.open(path, key: key);
opened.close();

On a phone, use path_provider application-documents or support directory, not the project folder.

5. Delete the database

db.close();
File(path).deleteSync();
final wal = File('$path-wal');
if (wal.existsSync()) wal.deleteSync();

6. Collections

db.insert('users', '{"name":"Ada","age":36}');
print(db.listCollections());
db.renameCollection('users', 'people');
db.dropCollection('people');

7. Documents

final id = db.insert('users', '{"name":"Ada","age":36}');
db.insertMany('users', '[{"name":"Grace","age":85}]');
final ada = db.findById('users', id);
db.replace('users', '{"_id":"$id","name":"Ada Lovelace","age":36}');
db.deleteById('users', id);
final rows = db.execute(r'db.users.find({ age: { $gte: 21 } }).limit(20)');

8. Password for an encrypted file

On mobile, keep the key in the platform secure store (flutter_secure_storage or equivalent). Do not bake 1234 into Dart source.

db.changeEncryptionKey(currentKey, nextKey);

See Encryption notes.

Discussion

Comment on NuvexaDB. The thread lives on this component's GitHub repository (nuvyntralabs/NuvexaDB). Sign in with GitHub — Giscus uses Discussions, Utterances uses Issues.