dart:js_interop
LogoDart

dart:js_interop#

Interoperability, "interop" for short, with JavaScript and browser APIs.

JavaScript interop allows a Dart program to interact with a JavaScript runtime. This can, for example, be to access JavaScript declarations and interact with JavaScript values, or to adapt Dart values so that they can be passed to and used by JavaScript code.

This JavaScript interop library works by introducing an abstraction over JavaScript values, a Dart type hierarchy ("JS types") which mirrors known JavaScript types, and a framework for introducing new Dart types that bind Dart type declarations to JavaScript values and external member declarations to JavaScript APIs.

This abstraction allows the same interop API to be used both when the Dart code is compiled to JavaScript and when compiled to Wasm.

See https://dart.dev/interop/js-interop for more details on usage, types, and previous JavaScript interop.

The types defined in this library only provide static guarantees. The runtime types differ based on the backend, so it is important to rely on static functionality like the conversion functions. Similarly, don't rely on is checks that involve JS types or JS-typed values. Furthermore, identical may also return different results for the same JS value depending on the compiler. Use == to check for equality of two JS-typed values instead, but do not check for equality between a Dart value and a JS-typed value.

Classes#

ClassDescription
JS An annotation on a JavaScript interop declaration.
JSExport Annotation to allow Dart classes to be wrapped with a JS object using dart:js_interop 's createJSInteropWrapper .

Exceptions#

ExceptionDescription
NullRejectionException Exception for when a JSPromise that is converted via JSPromiseToFuture.toDart is rejected with a null or undefined value.

Extensions#

ExtensiononDescription
BoolToJSBoolean bool Conversions from bool to JSBoolean .
ByteBufferToJSArrayBuffer ByteBuffer Conversions from ByteBuffer to JSArrayBuffer .
ByteDataToJSDataView ByteData Conversions from ByteData to JSDataView .
DoubleToJSNumber double Conversions from double to JSNumber .
ExternalDartReferenceToObject<T extends Object?> ExternalDartReference<T> Conversions from ExternalDartReference to the value of type T .
Float32ListToJSFloat32Array Float32List Conversions from Float32List to JSFloat32Array .
Float64ListToJSFloat64Array Float64List Conversions from Float64List to JSFloat64Array .
FunctionToJSExportedDartFunction Function Conversions from Function to JSExportedDartFunction .
FutureOfJSAnyToJSPromise<T extends JSAny?> Future<T> Conversions from Future to JSPromise where the Future returns a value.
FutureOfVoidToJSPromise Future<void> Conversions from Future to JSPromise where the Future does not return a value.
Int16ListToJSInt16Array Int16List Conversions from Int16List to JSInt16Array .
Int32ListToJSInt32Array Int32List Conversions from Int32List to JSInt32Array .
Int8ListToJSInt8Array Int8List Conversions from Int8List to JSInt8Array .
JSAnyOperatorExtension JSAny? General-purpose JavaScript operators.
JSAnyUtilityExtension JSAny? Common utility functions that are useful for any JavaScript value.
JSArrayBufferToByteBuffer JSArrayBuffer Conversions from JSArrayBuffer to ByteBuffer .
JSArrayToList<T extends JSAny?> JSArray<T> Conversions from JSArray to List .
JSBooleanToBool JSBoolean Conversions from JSBoolean to bool .
JSBoxedDartObjectToObject JSBoxedDartObject Conversions from JSBoxedDartObject to Object .
JSDataViewToByteData JSDataView Conversions from JSDataView to ByteData .
JSExportedDartFunctionToFunction JSExportedDartFunction Conversions from JSExportedDartFunction to Function .
JSFloat32ArrayToFloat32List JSFloat32Array Conversions from JSFloat32Array to Float32List .
JSFloat64ArrayToFloat64List JSFloat64Array Conversions from JSFloat64Array to Float64List .
JSFunctionUtilExtension JSFunction Utility extensions for JSFunction .
JSInt16ArrayToInt16List JSInt16Array Conversions from JSInt16Array to Int16List .
JSInt32ArrayToInt32List JSInt32Array Conversions from JSInt32Array to Int32List .
JSInt8ArrayToInt8List JSInt8Array Conversions from JSInt8Array to Int8List .
JSNumberToNumber JSNumber Conversions from JSNumber to double or int .
JSPromiseToFuture<T extends JSAny?> JSPromise<T> Conversions from JSPromise to Future .
JSStringToString JSString Conversions from JSString to String .
JSUint16ArrayToUint16List JSUint16Array Conversions from JSUint16Array to Uint16List .
JSUint32ArrayToUint32List JSUint32Array Conversions from JSUint32Array to Uint32List .
JSUint8ArrayToUint8List JSUint8Array Conversions from JSUint8Array to Uint8List .
JSUint8ClampedArrayToUint8ClampedList JSUint8ClampedArray Conversions from JSUint8ClampedArray to Uint8ClampedList .
ListToJSArray<T extends JSAny?> List<T> Conversions from List to JSArray .
NullableObjectUtilExtension Object? Common utility functions for <code> Object ?</code>s.
NullableUndefineableJSAnyExtension JSAny? Helper members to determine if a value is JavaScript undefined or null.
NumToJSExtension num Conversions from num to JSNumber .
ObjectToExternalDartReference<T extends Object?> T Conversions from a value of type T to ExternalDartReference .
ObjectToJSBoxedDartObject Object Conversions from Object to JSBoxedDartObject .
StringToJSString String Conversions from String to JSString .
Uint16ListToJSUint16Array Uint16List Conversions from Uint16List to JSUint16Array .
Uint32ListToJSUint32Array Uint32List Conversions from Uint32List to JSUint32Array .
Uint8ClampedListToJSUint8ClampedArray Uint8ClampedList Conversions from Uint8ClampedList to JSUint8ClampedArray .
Uint8ListToJSUint8Array Uint8List Conversions from Uint8List to JSUint8Array .

Extension Types#

Extension TypeDescription
ExternalDartReference<T extends Object?> An opaque reference to a Dart object that can be passed to JavaScript.
JSAny A non-nullish JavaScript value.
JSArray<T extends JSAny?> A JavaScript Array.
JSArrayBuffer A JavaScript ArrayBuffer.
JSBigInt A JavaScript BigInt .
JSBoolean A JavaScript boolean.
JSBoxedDartObject A Dart object that is wrapped with a JavaScript object so that it can be passed to JavaScript safely.
JSDataView A JavaScript DataView.
JSExportedDartFunction A JavaScript callable function created from a Dart function.
JSFloat32Array A JavaScript Float32Array.
JSFloat64Array A JavaScript Float64Array.
JSFunction A JavaScript Function value.
JSInt16Array A JavaScript Int16Array .
JSInt32Array A JavaScript Int32Array .
JSInt8Array A JavaScript Int8Array .
JSNumber A JavaScript number.
JSObject A JavaScript Object.
JSPromise<T extends JSAny?> A JavaScript Promise or a promise-like object.
JSString A JavaScript string.
JSSymbol A JavaScript Symbol .
JSTypedArray Abstract supertype of all JavaScript typed arrays.
JSUint16Array A JavaScript Uint16Array .
JSUint32Array A JavaScript Uint32Array .
JSUint8Array A JavaScript Uint8Array .
JSUint8ClampedArray A JavaScript Uint8ClampedArray.

Functions#

FunctionDescription
createJSInteropWrapper<T extends Object> Given a instance of a Dart class that contains an <code>@ JSExport </code> annotation, creates a JavaScript object that wraps the given Dart object.
importModule Dynamically imports a JavaScript module with the given moduleName using the JavaScript import() syntax.

Properties#

PropertyDescription
globalContext The global scope that is used to find user-declared interop members.

Constants#

ConstantDescription
anonymous An annotation that indicates a JS annotated class is structural and does not have a known JavaScript prototype.
staticInterop staticInterop enables the JS annotated class to be treated as a "static" interop class.

Typedefs#

TypedefDescription
JSVoid JS type equivalent for undefined for interop member return types.