Skip to main content

Integrating with Web

Refer to the Web setup page for required installables.

Once you have installed the required dependencies, you will need to create a wrapper to consume the bridge files. In the case of DynamicLibrary you only needed to supply the path to the binary, but to import a WASM module you need to:

  • Create a script tag to the JS file generated by wasm_bindgen and insert it into the document;
  • Invoke the wasmModule initializer defined in the web bridge;
  • And finally, create the implementation class.

Create a Dart file and copy these lines to it:

import 'bridge_generated.web.dart';
export 'bridge_definitions.dart';

import 'dart:html';

// Path to the wasm_bindgen generated files
const root = 'pkg/native';
final api = NativeImpl.wasm(WasmModule.initialize(
kind: const Modules.noModules(root: root),
));