Closed RickVM closed 2 years ago
dart:html is used only in browser side development as far as I know, please show me where this is used on server side android(flutter) builds. Are you building the server client or the browser client?
Also the pub.dev information is generated by Google, not me so there's not much I can do about this.
Ah, it seems I was confused by the naming of the android/ios/desktop; server_client.
Have not tried to run that one but I imagine this solves the issue.
Perhaps other names are less confusing? e.g. "mqtt_browser_client" and "mqtt_general_client"?
Hi I'm trying to build app for web/iOs/Android, and this code get error
if (kIsWeb) {
// Web
logger.e(devid);
client = MqttBrowserClient('ws://webaddress/mqtt', '');
client!.websocketProtocols = MqttClientConstants.protocolsSingleDefault;
client!.port = 8083;
} else {
// iOS and MacOS and Android
client = MqttServerClient('webaddress', '');
client!.port = 1883;
}
So I used both MqttBrowser and MqttServerClient in one code. Compiling to web works perfect, but compiling to iOs or Android make errors:
../flutter/.pub-cache/hosted/pub.dartlang.org/mqtt_client-9.6.3/lib/mqtt_browser_client.dart:11:8: Error: Not found: 'dart:html' import 'dart:html'; ^ ../flutter/packages/flutter/lib/src/foundation/_platform_web.dart:5:8: Error: Not found: 'dart:html' import 'dart:html' as html; ^ ../flutter/.pub-cache/hosted/pub.dartlang.org/mqtt_client-9.6.3/lib/src/connectionhandling/browser/mqtt_client_mqtt_browser_ws_connection.dart:52:16: Error: The method 'WebSocket' isn't defined for the class 'MqttBrowserWsConnection'.
- 'MqttBrowserWsConnection' is from 'package:mqtt_client/mqtt_browser_client.dart' ('../flutter/.pub-cache/hosted/pub.dartlang.org/mqtt_client-9.6.3/lib/mqtt_browser_client.dart'). Try correcting the name to the name of an existing method, or defining a method named 'WebSocket'. client = WebSocket(uriString, protocols); ^^^^^^^^^ ../flutter/.pub-cache/hosted/pub.dartlang.org/mqtt_client-9.6.3/lib/src/connectionhandling/browser/mqtt_client_mqtt_browser_ws_connection.dart:117:16: Error: The method 'WebSocket' isn't defined for the class 'MqttBrowserWsConnection'.
- 'MqttBrowserWsConnection' is from 'package:mqtt_client/mqtt_browser_client.dart' ('../flutter/.pub-cache/hosted/pub.dartlang.org/mqtt_client-9.6.3/lib/mqtt_browser_client.dart'). Try correcting the name to the name of an existing method, or defining a method named 'WebSocket'. client = WebSocket(uriString, protocols); ^^^^^^^^^ ../flutter/.pub-cache/hosted/pub.dartlang.org/mqtt_client-9.6.3/lib/src/connectionhandling/browser/mqtt_client_mqtt_browser_connection.dart:44:32: Error: 'MessageEvent' isn't a type. client.onMessage.listen((MessageEvent e) { ^^^^^^^^^^^^ ../flutter/packages/flutter/lib/src/foundation/_platform_web.dart:25:12: Error: Getter not found: 'debugEmulateFlutterTesterEnvironment'. if (ui.debugEmulateFlutterTesterEnvironment as bool) { ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ../flutter/packages/flutter/lib/src/foundation/_platform_web.dart:40:41: Error: Getter not found: 'window'. final String navigatorPlatform = html.window.navigator.platform?.toLowerCase() ?? ''; ^^^^^^ ../flutter/packages/flutter/lib/src/foundation/_platform_web.dart:60:12: Error: Getter not found: 'window'. if (html.window.matchMedia('only screen and (pointer: fine)').matches) {
When I removed MqttBrowserClient from code, it works perfect on iOs and Android
You can't mix the two clients in the same code for both web and server platforms as you have found, if you want to select between them you have to use conditional imports as shown in the mqtt_client_universal.dart example. Closing this issue.
Hi there,
on pub.dev the package states that android, ios, linux, macos and windows are supported platforms. This doesnt seem to be the case however, compiling for android fails since dart:html is used, the description also mentions browser giving a hint that only the browser might be supported.
Best fix would be to support all platforms :D but if not, please remove the false info on pub.dev so nobody has to find out only web is supported after integrating this package and going cross-platform.