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

question: build error while adding an event listener #227

Closed
caleb-at-pieces opened this issue Apr 25, 2024 · 2 comments
Closed

question: build error while adding an event listener #227

caleb-at-pieces opened this issue Apr 25, 2024 · 2 comments

Comments

@caleb-at-pieces
Copy link

I am attempting to add an event listener on the window like so:

import 'dart:html';
import 'dart:js_interop';
import 'package:web/web.dart' as js;


void main() {
  runApp(const MyApp());
  try {
    js.window.addEventListener('message', test.toJS);
  } catch (e) {
    print('there was an err $e');
  }
}

void test(Event _) {
  print('test invoked');
}

however whenever I try to build my application I get this build error:

image

I saw someone faced this same issue here #212 (comment) however after trying to replicate their code I still face the same issue

@caleb-at-pieces
Copy link
Author

alright my issue was I was importing the 'Event' type from the dart:html package instead of the package:web/web.dart package

I'm all good now!

@srujzs
Copy link
Contributor

srujzs commented Apr 25, 2024

If you upgrade your SDK to something like 3.4, we've actually enabled this behavior (to use a dart:html type in a function that gets toJS'd) so that code can be a bit easier to migrate from dart:html to package:web. Granted, dart:html still won't work on dart2wasm. At any rate, it looks like using the dart:html type wasn't your intention anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants