createJSInteropWrapper<T extends Object> function

JSObject createJSInteropWrapper<T extends Object>(
  1. T dartObject
)

Given a Dart object that is marked "exportable", creates a JS object that wraps the given Dart object. Look at the @JSExport annotation to determine what constitutes "exportable" for a Dart class. The object literal will be a map of export names (which are either the written instance member names or their rename) to their respective Dart instance members.

For example:

import 'dart:js_interop';

import 'package:expect/expect.dart';

@JSExport()
class ExportCounter {
  @JSExport('value')
  int counterValue = 0;
  String stringify() => counterValue.toString();
}

extension type Counter(JSObject _) {
  external int get value;
  external set value(int val);
  external String stringify();
}

void main() {
  var export = ExportCounter();
  var counter = Counter(createJSInteropWrapper(export));
  export.counterValue = 1;
  Expect.equals(counter.value, export.counterValue);
  Expect.equals(counter.stringify(), export.stringify());
}

Implementation

external JSObject createJSInteropWrapper<T extends Object>(T dartObject);