How do I get js_interop working? #510
Answered
by
schultek
sethcalebweeks
asked this question in
Q&A
-
|
From what I've seen it looks like there was a recent move to using import 'package:jaspr/jaspr.dart';
@Import.onWeb('package:web/web.dart', show: [#window, #document])
@Import.onWeb('dart:js_interop', show: [#globalContext, #toJS])
import 'handsontable.imports.dart';
class Handsontable extends StatelessComponent {
const Handsontable({super.key});
@override
Iterable<Component> build(BuildContext context) sync* {
final containerId = 'hot-${DateTime.now().millisecondsSinceEpoch}';
void callback() {
print("hello wrld");
}
if (kIsWeb) {
final asdf = document.getElementById(containerId);
globalContext.callMethod('_showAlert'.toJS, ['hello world'.toJS]);
print(asdf);
}
yield div(id: containerId, [text('Hello World')]);
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
schultek
Jul 29, 2025
Replies: 1 comment 2 replies
-
|
There are two parts to this.
|
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
sethcalebweeks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are two parts to this.
package:universal_web, which already does the conditional import and stubbing for you, so you replace bothpackage:webanddart:js_interopimports and don't need to use@Import.window.alert()). For anything custom you should use the new js_interop way of doing things: https://dart.dev/interop/js-interop/usage#top-level-interop-members