Closed hoangquocan closed 7 months ago
There could be issues with initializing the WASM module if the wire_* functions are not available. I'm also trying to set up an HTTPS server on local for troubleshooting this issue, but more details would definitely be helpful.
i try firebase deploy with simple example like that:
pub fn greet() -> Result<String>{ Ok("Hello world from Rust!".to_string()) }
import "package:flutter/material.dart";
import '../ffi.io.dart' if (dart.library.html) '../ffi.web.dart';
export '../ffi.io.dart' if (dart.library.html) '../ffi.web.dart' show api;
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
String _greet = "";
@override
void initState() {
_callRustFfi();
super.initState();
}
Future<void> _callRustFfi() async {
final result = await api.greet();
if (mounted) setState(() => _greet = result);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: Text(_greet),
)),
);
}
}
and in ffi.web.dart:
// ignore_for_file: avoid_web_libraries_in_flutter
import 'dart:html';
import 'package:flutter_rust_bridge/flutter_rust_bridge.dart';
import 'bridge_generated.web.dart';
const root = 'pkg/native';
Future<WasmModule> _initModule() {
if (crossOriginIsolated != true) {
return Future.error(const MissingHeaderException());
}
final script = ScriptElement()..src = '$root.js';
document.head!.append(script);
return script.onLoad.first.then((_) {
eval("window.wasm_bindgen = wasm_bindgen");
return wasmModule.bind(wasmModule, '${root}_bg.wasm');
});
}
final api = NativeImpl.wasm(_initModule());
i wonder if i just need to use build/web folder has compiled by just serve
command then firebase deploy
?
This issue has been marked as stale because it has no activity recently. Please remove the 'stale' label, or comment if the issue persists.
This issue has been closed after a period of inactivity. Please reopen this issue if the problem persists, or open a new one if you have a similar problem.
Hi! I'm using this Template since FRB v1.75, it almost works Well for all my cases. When i want to deploy with Web Platform, it can not use function from Rust (in dev mode it has no problem). it also has no CORS error, only error like my Attachments. Sorry about my English not well and Issue in deployment seems little for research!