shamblett / mqtt_client

A server and browser based MQTT client for dart
Other
548 stars 176 forks source link

type 'List<ChangeRecord>' is not a subtype of type 'List<MqttReceivedMessage<dynamic>> #16

Closed LuLeRoemer closed 5 years ago

LuLeRoemer commented 6 years ago

Unfortunately, I get the following error running the example code:

E/flutter (16017): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (16017): type 'List<ChangeRecord>' is not a subtype of type 'List<MqttReceivedMessage<dynamic>>'
E/flutter (16017): #0      ChangeNotifier.deliverChanges (package:observable/src/change_notifier.dart:63:20)
E/flutter (16017): #1      _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (16017): #2      _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

It seems, there is a problem regarding publish messages. I'm using flutter v0.5.1.

shamblett commented 6 years ago

Yes, this looks like a Dart 2 problem, flutter users have been reporting this type of breakage in various parts of the client, it seems to change depending on the flutter version being used. When Google release Dart 2 into production I'll update and fix the client accordingly, until then there's not much I can do.

benbehringer commented 6 years ago

I added a workaround in my repo:

pubspec.yaml:

#mqtt_client: "^1.7.2"
mqtt_client:
git:
url: https://github.com/benbehringer/mqtt_client.git

subscribe as follows:

import 'package:observable/observable.dart' as observe;
import 'package:mqtt_client/mqtt_client.dart' as mqtt;

final observe.ChangeNotifier<observe.ChangeRecord> cn = client.subscribe(topic, mqtt.MqttQos.exactlyOnce).observable;
cn.changes.listen((List<observe.ChangeRecord> c) {
mqtt.MqttReceivedMessage myMessage = c[0] as mqtt.MqttReceivedMessage;
final mqtt.MqttPublishMessage recMess = myMessage.payload as mqtt.MqttPublishMessage;
final String pt =
mqtt.MqttPublishPayload.bytesToStringAsString(recMess.payload.message);
print("EXAMPLE::Change notification:: payload is <$pt> for topic <$topic>");
});

my config:

Flutter 0.5.6 • channel dev • https://github.com/flutter/flutter.git
Framework • revision 472bbccf75 (2 weeks ago) • 2018-06-26 17:01:46 -0700
Engine • revision 6fe748490d
Tools • Dart 2.0.0-dev.63.0.flutter-4c9689c1d2
cwitte4191 commented 6 years ago

thanks @benbehringer for sharing your fork. It helped me resume progress on my flutter project. Since this project is tagged as supporting flutter, it seems that this issue should reach a more concrete resolution. At a minimum, maybe the docs and example should be updated with some footnotes and links regarding the problems with dart 2, and by extension, flutter.

shamblett commented 6 years ago

Ok looks as though Dart 2 has hit stable, im just finishing my hols at the mo Ill update the package late this week/early next and see where we are then

shamblett commented 6 years ago

Dart 2.0 updates are now tracked on issue 24

shamblett commented 6 years ago

I believe the latest client(3.2.1) and flutter are now OK together, can you verify this.

shamblett commented 5 years ago

Believe this is now fixed.

excode commented 5 years ago

Can we use Mqtt_client for chatting app which will run both on IOS and Android. Please suggest. Thanks a lot

shamblett commented 5 years ago

I believe some users do use the client for stuff like this using flutter so you can run it on IOS or Android, some users use it as a general purpose pub/sub mechanism, you will of course need your own MQTT broker somewhere, the mqtt_client is as it says only a client.

ddkoin commented 5 years ago

I believe some users do use the client for stuff like this using flutter so you can run it on IOS or Android, some users use it as a general purpose pub/sub mechanism, you will of course need your own MQTT broker somewhere, the mqtt_client is as it says only a client.

Thanks.

Do you have any reference link / example for code which implement the mqtt_client for chat or pub/sub. Thanks in advance.