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

dart:html type error while adding event listener #35047

Open
ghost opened this issue Nov 4, 2018 · 0 comments
Open

dart:html type error while adding event listener #35047

ghost opened this issue Nov 4, 2018 · 0 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-libraries Issues impacting dart:html, etc., libraries

Comments

@ghost
Copy link

ghost commented Nov 4, 2018

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test</title>
    <script defer src="index.dart.js"></script>
</head>
<body>
</body>
</html>

index.dart:

import 'dart:html' as html;

void main(){
  var listener = html.window.onMouseMove.listen((e) {})
    ..onData((e) {
      var messageData = {
        'y': e.client.y,
        'x': e.client.x,
      };
      print('message data is ${messageData}');
    });
}

pubspec.yaml:

name: crash_test
version: 0.0.1
description:
homepage:
documentation:
author:
environment:
  sdk: '>=2.0.0 <3.0.0'

dependencies:

dev_dependencies:
  build_runner: any
  build_web_compilers: any

build.yaml:

targets:
  $default:
    builders:
      build_web_compilers|entrypoint:
        options:
          compiler: dart2js
          dart2js_args:
            - --csp

steps to reproduce:

pub run build_runner build --output build

Run above command then open build/web/index.html then see console output, it will display this message:

js_helper.dart:1763 Uncaught Error: TypeError: Closure 'main_closure0': 
type '(MouseEvent) => Null' is not a subtype of type '(Event) => void'
    at Object.wrapException (js_helper.dart:1763)
    at Object.functionTypeCheck (js_helper.dart:3783)
    at Object.main (html_dart2js.dart:35700)
    at index.dart.js:5209
    at index.dart.js:5193
    at index.dart.js:5204
    at index.dart.js:5212

Above issue is resolved after passing these arguments to dart2js:

dart2js_args:
            - --fast-startup
            - --minify
            - --omit-implicit-checks
            - --trust-primitives
            - --csp
@dgrove dgrove added the web-libraries Issues impacting dart:html, etc., libraries label Nov 5, 2018
@vsmenon vsmenon added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Jul 21, 2019
@vsmenon vsmenon removed their assignment Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-libraries Issues impacting dart:html, etc., libraries
Projects
None yet
Development

No branches or pull requests

2 participants