dart:html not found -> cannot use WebSockets

Viewed 14

I'm trying to build a WebSocket client app for my C# server and fail already at importing basic dart libraries:

bin/rpc_dart_test.dart:2:8: Error: Not found: 'dart:html'
import 'dart:html';
       ^
bin/rpc_dart_test.dart:50:16: Error: Couldn't find constructor 'WebSocket'.
  var ws = new WebSocket("ws://localhost:7077/ws");
               ^^^^^^^^^
bin/rpc_dart_test.dart:51:24: Error: 'MessageEvent' isn't a type.
  ws.onMessage.listen((MessageEvent e) {
                       ^^^^^^^^^^^^
bin/rpc_dart_test.dart:54:38: Error: Undefined name 'WebSocket'.
  if (ws != null && ws.readyState == WebSocket.OPEN) {
                                     ^^^^^^^^^

How can I make this work? Just removing the import line as recommended in some Google results only makes the first error go away, but doesn't help in general. Changing from dart:html to package:http/http.dart neither works, because there is no WebSocket class in that package.

0 Answers
Related