web_bridge library
Everything a generated *.web.bridge.g.dart needs, resolved to the WEB
implementations unconditionally.
Generated web bridges import THIS library instead of package:nitro/nitro.dart:
the main barrel's conditional exports resolve per-platform (native under
the analyzer), while a web bridge must always see the web runtime —
NitroRuntime.loadWebModule, NitroWasmModule, WasmArena, the
framed-bytes RecordReader/RecordWriter, and friends.
Do NOT import this from code that also runs natively — use
package:nitro/nitro.dart there.
Classes
- AndroidNativeImpl
- Accepted by NitroModule.android.
- AnyNativeObject
- An opaque reference to any registered native implementation.
- AppleNativeImpl
- Accepted by NitroModule.ios and NitroModule.macos.
- ByteBuffer
- A sequence of bytes underlying a typed data object.
- ByteData
- A fixed-length, random-access sequence of bytes that also provides random and unaligned access to the fixed-width integers and floating point numbers represented by those bytes.
- BytesBuilder
- Builds a list of bytes, allowing bytes and lists of bytes to be added at the end.
- CppImpl
- Direct C++ via CMake/FFI. Valid on all native platforms. Implements all native-platform sealed interfaces so it is accepted by every NitroModule platform field except NitroModule.web.
- Double
- Endian
- Endianness of number representation.
- Float
- Float32List
- A fixed-length list of IEEE 754 single-precision binary floating-point numbers that is viewable as a TypedData.
- Float32x4
- Four 32-bit floating point values.
- Float32x4List
- A fixed-length list of Float32x4 numbers that is viewable as a TypedData.
- Float64List
- A fixed-length list of IEEE 754 double-precision binary floating-point numbers that is viewable as a TypedData.
- Float64x2
- Float64x2 immutable value type and operations.
- Float64x2List
- A fixed-length list of Float64x2 numbers that is viewable as a TypedData.
- HybridEnum
- HybridObject
- HybridRecord
- Marks a Dart class as a rich, binary-serialized record type for use as method parameters, return types, or stream items in a @NitroModule.
- HybridStruct
- Value type that bridges with C-ABI struct layout.
- Int16
- Int16List
- A fixed-length list of 16-bit signed integers that is viewable as a TypedData.
- Int32
- Int32List
- A fixed-length list of 32-bit signed integers that is viewable as a TypedData.
- Int32x4
- Int32x4 and operations.
- Int32x4List
- A fixed-length list of Int32x4 numbers that is viewable as a TypedData.
- Int64
- Int64List
- A fixed-length list of 64-bit signed integers that is viewable as a TypedData.
- Int8
- Markers for the fixed-width dart:ffi types, so type-parameter positions in shared code keep compiling on web.
- Int8List
- A fixed-length list of 8-bit signed integers.
- KotlinImpl
- Kotlin + JNI bridge. Valid on Android only.
- LinuxNativeImpl
- Accepted by NitroModule.linux.
- MainThread
-
NativeHandle<
T> -
Web twin of the native
NativeHandle<T>. - NativeImpl
- Backward-compatible shorthand namespace. Prefer the per-platform constants (AppleNativeImpl, AndroidNativeImpl, WindowsNativeImpl, LinuxNativeImpl, WebNativeImpl) for clarity.
- NativeType
- Marker supertype mirroring dart:ffi's NativeType.
- NitroAnyBool
- NitroAnyDouble
- NitroAnyInt
- NitroAnyList
- NitroAnyMap
- NitroAnyNull
- NitroAnyObject
- NitroAnyString
- NitroAnyValue
- NitroAsync
- NitroBoolWireCodec
-
Built-in wire codec for
bool?— the byte layout ofNitroOptBool([1B hasValue][1B value], packed). - NitroCoalescer
-
Web twin of
NitroCoalescer— demultiplexer for coalesced@nitroNativeAsynccompletions, backed by a WebReceivePort instead of aReceivePort. - NitroConfig
- Global configuration for the Nitro runtime.
- NitroCustomType
- Registers a Dart class as a custom FFI bridge type encoded by a NitroFfiCodec.
- NitroDoubleWireCodec
-
Built-in wire codec for
double?— the byte layout ofNitroOptFloat64([1B hasValue][8B float64 LE], packed). -
NitroErr<
T extends Object?> - Failure case — carries the native-side error message.
- NitroInstanceRegistry
- Dart-side registry mapping native instance IDs to live impl objects.
- NitroIntWireCodec
-
Built-in wire codec for
int?— the byte layout ofNitroOptInt64([1B hasValue][8B int64 LE], packed). - NitroModule
- NitroNativeAsync
- NitroNullableBool
-
Collision-free nullable
boolfor Nitro bridges. - NitroNullableDouble
-
Collision-free nullable
doublefor Nitro bridges. - NitroNullableInt
-
Collision-free nullable
intfor Nitro bridges. -
NitroOk<
T extends Object?> - Success case — carries the native return value.
- NitroOwned
- Marks that the native side heap-allocates the returned NativeHandle and Dart takes ownership. The generator will:
-
NitroPromise<
T> -
A composable async primitive that mirrors RN Nitro's
Promise<T>. - NitroResult
- Marks a method's return type as a discriminated success/error result.
-
NitroResultValue<
T extends Object?> -
Discriminated success/error result for native methods annotated with
@NitroResult(). - NitroRuntime
- The runtime is called only by generated code. Plugin authors and app developers interact with NitroConfig instead.
- NitroStream
- NitroStreamBatch
-
@NitroStream with batch backpressure configuration.
Example:
@NitroStream(backpressure: Backpressure.batch, batchMaxSize: 64) - NitroTuple
- Marks a Dart 3 positional record typedef as a named tuple type.
- NitroVariant
- Marks a Dart sealed class as a discriminated union type (sum type / tagged union).
- NitroWasmModule
- A loaded nitro WASM module: the Emscripten Module object plus typed heap I/O and the module-allocator entry points generated bridges rely on.
- NitroWebPorts
- Registry mapping integer port ids to message handlers — the web analog of the VM's native-port table.
-
NitroWireCodec<
T extends Object> -
Platform-neutral codec for a
@NitroCustomTypeTtransported across the bridge as an optional fixed-size value:[1B hasValue][encodedSize-1 bytes]. - RecordReader
- Streaming binary reader for @HybridRecord types (web edge).
- RecordReaderBase
- Platform-neutral core of the @HybridRecord binary reader.
- RecordWriter
- Streaming binary writer for @HybridRecord types (web edge).
- RecordWriterBase
- Platform-neutral core of the @HybridRecord binary writer.
- SwiftImpl
- Swift + @_cdecl bridge. Valid on Apple platforms (iOS and macOS) only.
- TypedData
- A typed view of a sequence of bytes.
-
TypedDataList<
E> - A TypedData fixed-length List-view on the bytes of buffer.
- Uint16
- Uint16List
- A fixed-length list of 16-bit unsigned integers that is viewable as a TypedData.
- Uint32
- Uint32List
- A fixed-length list of 32-bit unsigned integers that is viewable as a TypedData.
- Uint64
- Uint64List
- A fixed-length list of 64-bit unsigned integers that is viewable as a TypedData.
- Uint8
- Uint8ClampedList
- A fixed-length list of 8-bit unsigned integers.
- Uint8List
- A fixed-length list of 8-bit unsigned integers.
- Void
-
Marker mirroring dart:ffi's Void (e.g.
NativeHandle<Void>). - WasmArena
-
Scoped allocator over a WASM module heap — the web analog of package:ffi's
Arena. Every allocation is freed when the scope exits. - WasmImpl
- WASM/JS interop bridge. Valid on Web only — dart:ffi is unavailable on web.
- WebNativeImpl
- Accepted by NitroModule.web.
- WebNitroErrorSlot
-
The C
NitroErrorout-param struct read from WASM linear memory. - WebReceivePort
-
Web stand-in for
dart:isolate's ReceivePort, backed by NitroWebPorts. - WebSendPort
-
Facade mirroring
SendPortfor WebReceivePort. - WindowsNativeImpl
- Accepted by NitroModule.windows.
- ZeroCopy
- ZeroCopyBuffer
-
Buffer of
uint8_t— maps to Uint8List. Web: one bulk copy at creation. - ZeroCopyFloat32Buffer
-
Buffer of
float— maps to Float32List. - ZeroCopyFloat64Buffer
-
Buffer of
double— maps to Float64List. - ZeroCopyInt16Buffer
-
Buffer of
int16_t— maps to Int16List. - ZeroCopyInt32Buffer
-
Buffer of
int32_t— maps to Int32List. - ZeroCopyInt64Buffer
-
Buffer of
int64_t— maps to Int64List. - ZeroCopyInt8Buffer
-
Buffer of
int8_t— maps to Int8List. - ZeroCopyUint16Buffer
-
Buffer of
uint16_t— maps to Uint16List. - ZeroCopyUint32Buffer
-
Buffer of
uint32_t— maps to Uint32List.
Enums
- Backpressure
- NitroLogLevel
- Log verbosity levels for NitroConfig.logLevel.
- NitroPromiseState
- Observable state of a NitroPromise.
Extension Types
- EmscriptenModule
-
The Emscripten
Moduleobject of a loaded nitro WASM module.
Extensions
Constants
- hybridRecord → const HybridRecord
- kNitroAnyMapKotlinHelper → const String
- Kotlin inline encoder/decoder source, emitted as a string constant for the generator to inject into bridge .kt files.
- kNitroAnyMapSwiftHelper → const String
- Swift inline encoder/decoder source, emitted by the generator into bridge .swift files.
- kNitroWeb → const bool
- True when compiling for the web (dart2js or dart2wasm). A compile-time constant, so each compiler tree-shakes the other branch below.
- mainThread → const MainThread
- Runs the Kotlin/Swift implementation of this method on the platform's main/UI thread instead of the calling thread.
- nitroAsync → const NitroAsync
- nitroNativeAsync → const NitroNativeAsync
- nitroOwned → const NitroOwned
-
Const shorthand for
@NitroOwned. - nitroResult → const NitroResult
-
Const shorthand for
@NitroResult. - nitroVariant → const NitroVariant
-
Const shorthand for
@NitroVariant. - utf8 → const Utf8Codec
- An instance of the default implementation of the Utf8Codec.
- utf8DecoderAllowMalformed → const Utf8Decoder
- zeroCopy → const ZeroCopy
Functions
-
dartI64(
JSAny? v) → int -
JS BigInt (or number) → Dart int, for
int64_treturns and callback args. -
decodeUtf8NoBomStrip(
Uint8List bytes) → String - Decodes UTF-8 bytes to a Dart String without stripping leading U+FEFF. dart:convert's Utf8Decoder treats a leading BOM (U+FEFF / 0xEF 0xBB 0xBF) as a stream signature and drops it. Bridge strings are raw data, not streams.
-
getInt64LE(
ByteData data, int offset) → int -
Reads a little-endian int64 at
offset. -
jsI64(
int v) → JSAny -
Dart int → JS BigInt, for
int64_tparameters. -
jsonDecode(
String source, {Object? reviver(Object? key, Object? value)?}) → dynamic - Parses the string and returns the resulting Json object.
-
jsonEncode(
Object? object, {Object? toEncodable(Object? nonEncodable)?}) → String -
Converts
objectto a JSON string. -
nitroWebExportName(
String libName) → String -
Computes the Emscripten
EXPORT_NAMEfactory for a nitro lib name:benchmark_cpp→createBenchmarkCppModule. The CMake emitter uses the same convention — keep the two in sync. -
setInt64LE(
ByteData data, int offset, int value) → void -
Writes a little-endian int64 at
offset. See getInt64LE for the per-compiler contract. -
withWasmArena<
T> (NitroWasmModule module, T action(WasmArena arena)) → T -
Runs
actionwith a scoped WasmArena overmodule, freeing all arena allocations afterwards — the web analog ofwithArena/using.
Exceptions / Errors
- HybridException
- Represents a native exception propagated from Kotlin, Swift, or C++.