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.
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.
- webcrypto
Cross-platform implementation of Web Cryptography APIs for Dart.
89Compare - cryptography
Cross‑platform cryptographic algorithms for Dart and Flutter.
67Compare - universal_html
Cross‑platform replacement for dart:html with DOM parsing, XML support, and EventSource.
66Compare - const_date_time
A drop-in replacement for Dart's DateTime class with const constructors.
57Compare
Works with
Packages commonly used together with universal_ffi: ones it builds on, ones built on it, and its own family.
- ffiuniversal_ffi depends on itUtilities for working with Foreign Function Interface (FFI) code in Dart.
- wasm_ffiuniversal_ffi depends on itDrop-in replacement for dart:ffi for WebAssembly on the web platform.
- spine_flutterBuilt on universal_ffiOfficial Spine runtime for Flutter to load, display, and interact with skeletal animations.