Skip to content

SDK: Flutter/Dart bindings via flutter_rust_bridge #161

@saltyskip

Description

@saltyskip

Overview

Add a Flutter/Dart SDK by wrapping the existing core/ crate with a flutter_ffi/ crate using flutter_rust_bridge v2. Ships as a standalone pub.dev plugin package.

Architecture

The core/ crate already has no FFI dependency — no business logic needs to be duplicated.

core/         ← unchanged, pure Rust (attribution, identify, deferred deep links)
ffi/          ← UniFFI → Swift + Kotlin (existing native iOS/Android)
flutter_ffi/  ← flutter_rust_bridge → Dart (new)

Key work

1. client/mobile/flutter_ffi/ crate

  • Depends on rift_sdk_core
  • Mirrors the ffi/ public API surface using #[frb] annotations
  • Replicate all public methods: attributeLink, setUserId, checkDeferredDeepLink, pendingPresentation, dismissPresentation, showPresentation, etc.

2. RiftStorage equivalent for Dart

UniFFI's foreign trait pattern doesn't exist in flutter_rust_bridge. Instead, accept storage callbacks at init time backed by shared_preferences on the Dart side:

pub struct FlutterStorage {
    get: Arc<dyn Fn(String) -> Option<String> + Send + Sync>,
    set: Arc<dyn Fn(String, String) + Send + Sync>,
    remove: Arc<dyn Fn(String) + Send + Sync>,
}
final sdk = await RiftSdk.init(
  publishableKey: 'pk_live_...',
  storage: RiftStorage(
    get: (key) => prefs.getString(key),
    set: (key, val) => prefs.setString(key, val),
    remove: (key) => prefs.remove(key),
  ),
);

3. Flutter plugin package

  • flutter_rust_bridge_codegen generate produces Dart bindings
  • Plugin bundles compiled .so (Android) and .a (iOS) from the same Rust workspace
  • Publish to pub.dev

4. CI

  • Add Flutter build steps to sdk-ci.yml and sdk-release.yml alongside existing UniFFI bindgen
  • Triggered by sdk/flutter/ path changes

Out of scope

  • Native iOS/Android SDK changes (UniFFI path unchanged)
  • Any new business logic — all logic stays in core/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions