Skip to content
pubscout

web_ffi

0.7.2, released 5 years ago by eric-prokop-und-nils-wieler.de

Translates dart:ffi calls on the web to WebAssembly using dart:js.

WASM-ready
$ flutter pub add web_ffi
Source repository

What it does

Web_ffi allows developers to use a dart:ffi-compatible API on the web by translating calls through dart:js to a browser running WebAssembly compiled with emscripten. It introduces a Memory class to handle the memory model differences between native platforms and WebAssembly.

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

Use it when

  • You need to run WebAssembly code compiled with emscripten on the web using a dart:ffi-like API.
  • You are sharing existing C/C++ or WebAssembly logic that expects an ffi-like interface in a web Flutter application.

Skip it when

  • You are targeting native platforms where standard dart:ffi is already available.
  • Your WebAssembly modules require full struct support or array extensions which are not yet implemented.

Strengths

  • Provides a drop-in solution mimicking the dart:ffi API on the web.
  • Allows reuse of ffi-based patterns across web and native targets.

Weaknesses

  • Currently only supports WebAssembly compiled with emscripten.
  • Lacks support for structs (except opaque structs) and pointer array extensions.
  • Has strict constraints on function return types and pointer nesting.

Setup

Kind
Pure Dart
Effort
Medium
Code generation
No
Direct dependencies
2

Requires emscripten compiler settings and initializing Memory using Memory.init() before use.

import 'package:web_ffi/web_ffi.js';

void main() {
  Memory.init();
  // load and use your WebAssembly module
}

Alternatives

Packages that do the same job and could replace web_ffi.

Works with

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