Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider base href on the web #364

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions flutter_ffi_plugin/lib/src/load_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ Future<void> loadJsFile() async {
final loadCompleter = Completer<void>();
js.context['completeRinfLoad'] = loadCompleter.complete;

// Flutter app doesn't always have the top-level path of the domain.
// Sometimes, the flutter app might be placed in a lower path.
// This variable includes domain and the base path.
final baseHref = Uri.base;

// Use the default JavaScript path unless provided.
final path = jsLibPath ?? "/pkg/hub.js";
final path = jsLibPath ?? "pkg/hub.js";

final fullUrl = baseHref.resolve(path);
final scriptElement = ScriptElement();
scriptElement.type = "module";
scriptElement.innerHtml = '''
import init, * as wasmBindings from "$path";
import init, * as wasmBindings from "$fullUrl";
await init();
window.rinf = { ...wasmBindings };
completeRinfLoad();
Expand Down