Skip to content
pubscout

universal_ffi

1.5.1, released 3 months ago by vm75.duckdns.org

Cross-platform wrapper for dart:ffi and wasm_ffi to support native platforms and web.

WASM-ready
$ flutter pub add universal_ffi
Source repository

What it does

A thin cross-platform facade providing a consistent Foreign Function Interface (FFI) API across native platforms and the web using wasm_ffi. Includes helper utilities for platform-aware library loading and memory management.

AI-written summary of version 1.5.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to use FFI bindings in a Flutter or Dart project targeting both native and web platforms.
  • You want a unified way to load dynamic libraries or WebAssembly modules using FfiHelper.

Skip it when

  • Your project does not target the web and standard dart:ffi is sufficient.
  • You rely heavily on FFI features not supported on web by wasm_ffi, such as Array, Struct, or Union.

Strengths

  • Consistent API across all platforms including web
  • Helper utilities for asynchronous library loading and memory management

Weaknesses

  • Web platform has limitations on certain dart:ffi features like Array, Struct, and Union
  • Requires manual compilation and asset management for WebAssembly or Emscripten binaries

Setup

Kind
FFI (native library)
Effort
Medium
Code generation
No
Direct dependencies
3

Requires replacing standard dart:ffi imports with universal_ffi/ffi.dart, compiling C/C++ source code to shared libraries for desktop/mobile and WASM/JS for web, and setting up module loading.

import 'package:universal_ffi/ffi.dart';
import 'package:universal_ffi/ffi_helper.dart';
import 'package:universal_ffi/ffi_utils.dart';

void main() async {
  final ffiHelper = await FfiHelper.load('ModuleName');
  final bindings = WasmFfiBindings(ffiHelper.library);

  using((Arena arena) {
    // use bindings
  }, ffiHelper.library.allocator);
}

Alternatives

Packages that do the same job and could replace universal_ffi.

Works with

Packages commonly used together with universal_ffi: ones it builds on, ones built on it, and its own family.