0.1.7 • Published 6 years ago
flutter-web-wasm
Licence
—
Version
0.1.7
Deps
0
Size
26 kB
Vulns
0
Weekly
0
wasm-pack-template
A template for kick starting a Rust and WebAssembly project using wasm-pack.
Tutorial | Chat
Built with by The Rust and WebAssembly Working Group
About
This template is designed for compiling Rust libraries into WebAssembly and publishing the resulting package to NPM.
Be sure to check out other wasm-pack tutorials online for other
templates and usages of wasm-pack.
Usage
Use cargo generate to Clone this Template
Learn more about cargo generate here.
cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project
cd my-project
Build with wasm-pack build
wasm-pack build
Test in Headless Browsers with wasm-pack test
wasm-pack test --headless --firefox
Generate your dart bindings
rm -rf lib/src/flutter_web_wasm_base.dart
dart_js_facade_gen pkg/flutter_web_wasm.d.ts | tee lib/src/flutter_web_wasm_base.dart
Publish to NPM with wasm-pack publish
wasm-pack publish
Add your depedency Flutter side
In example/lib/web/index.html import your js library via script tag
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>example</title>
</head>
<body>
<script src="main.dart.js" type="application/javascript"></script>
<script src="https://unpkg.com/flutter-web-wasm@0.1.0/flutter_web_wasm.js"></script> <!-- Import your freshly generated library from unpk cdn -->
</body>
</html>
In your example/lib/main.dart import your library
import 'package:flutter_web_wasm/flutter_web_wasm.dart';
Batteries Included
wasm-bindgenfor communicating between WebAssembly and JavaScript.console_error_panic_hookfor logging panic messages to the developer console.wee_alloc, an allocator optimized for small code size.