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

StreamChannelMixin error since 2.1.3 #1947

Closed
redDwarf03 opened this issue Dec 23, 2024 · 9 comments · Fixed by #1957
Closed

StreamChannelMixin error since 2.1.3 #1947

redDwarf03 opened this issue Dec 23, 2024 · 9 comments · Fixed by #1957

Comments

@redDwarf03
Copy link

Since v2.1.3, i have this error

The class 'StreamChannelMixin' can't be used as a mixin because it's neither a mixin class nor a mixin.dart[class_used_as_mixin](https://dart.dev/diagnostics/class_used_as_mixin)
abstract class StreamChannelMixin<T> implements StreamChannel<T>
package:stream_channel/stream_channel.dart

A mixin that implements the instance methods of [StreamChannel] in terms of [stream] and [sink].

i don't see any updates about it in the changelog

@redDwarf03
Copy link
Author

@kevmoo 🙏🏼

@redDwarf03
Copy link
Author

my code


class MessagePortStreamChannel
    with StreamChannelMixin<String>
    implements StreamChannel<String> {
  MessagePortStreamChannel({required this.port}) {
    port.onmessage = (message) {
      _in.add(message.data! as String);
    }.toJS;

    _onPostMessageSubscription = _out.stream.listen((event) {
      port.postMessage(event as JSAny?);
    });
  }

  final MessagePort port;
  final _in = StreamController<String>(sync: true);
  final _out = StreamController<String>(sync: true);

  late final StreamSubscription<String> _onPostMessageSubscription;

  Future<void> dispose() async {
    await _onPostMessageSubscription.cancel();
    await _in.close();
    await _out.close();
  }

  @override
  StreamSink<String> get sink => _out.sink;

  @override
  Stream<String> get stream => _in.stream;
}


class WebBrowserExtensionStreamChannel
    with StreamChannelMixin<String>
    implements StreamChannel<String> {
  WebBrowserExtensionStreamChannel({required this.streamChannel}) {
    _onPostMessageSubscription = _out.stream.listen((event) async {
      _logger.info('[WBE] send command $event');
      await streamChannel.send(event as JSString).toDart;
      _logger.info('[WBE] send command Done');
    });
  }

  static final _logger = Logger('AWC-StreamChannel-WebBrowserExtention');

  Future<void> connect() async {
    final connectionCompleter = Completer<void>();

    streamChannel.onReady = () {
      _setupStreamChannel();
      connectionCompleter.complete();
    }.toJS;

    streamChannel.onClose = (String _) {
      connectionCompleter.completeError(Failure.connectivity);
    }.toJS;

    await streamChannel.connect().toDart;

    return connectionCompleter.future;
  }

  void _setupStreamChannel() {
    streamChannel.onReceive = (String message) {
      _logger.info('[WBE] command received $message');
      _in.add(message);
      _logger.info('[WBE] command received Done');
    }.toJS;

    streamChannel.onClose = (String reason) {
      unawaited(_onPostMessageSubscription.cancel());
      unawaited(_in.close());
      unawaited(_out.close());
    }.toJS;
  }

  final AWCStreamChannelJS streamChannel;
  final _in = StreamController<String>(sync: true);
  final _out = StreamController<String>(sync: true);

  late final StreamSubscription<String> _onPostMessageSubscription;

  Future<void> dispose() async {
    await streamChannel.close().toDart;
  }

  @override
  StreamSink<String> get sink => _out.sink;

  @override
  Stream<String> get stream => _in.stream;
}

@kevmoo
Copy link
Member

kevmoo commented Dec 23, 2024

I think this has to do w/ the SDK changing the model for mixins. What's your min Dart SDK?

@kevmoo
Copy link
Member

kevmoo commented Dec 23, 2024

Er, what Dart SDK are you using and what's the SDK constraint in your pubspec?

@redDwarf03
Copy link
Author

hello @kevmoo
Thank you for the reply
I would have imagined a major version change on the lib instead of a minor one with this breaking changes

[✓] Flutter (Channel stable, 3.24.5, on macOS 14.6.1 23G93 darwin-arm64, locale fr-FR)
    • Flutter version 3.24.5 on channel stable 
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision dec2ee5c1f (6 weeks ago), 2024-11-13 11:13:06 -0800
    • Engine revision a18df97ca5
    • Dart version 3.5.4
    • DevTools version 2.37.3

@kevmoo
Copy link
Member

kevmoo commented Dec 24, 2024

@redDwarf03 – what's the SDK constraint in your pubspec?

@redDwarf03
Copy link
Author

redDwarf03 commented Dec 24, 2024

@kevmoo here it is:

name: archethic_wallet_client
description: A client dart library to interact with Archethic Wallet RPC API.

version: 2.1.8

homepage: https://github.com/archethic-foundation/archethic-wallet-client-dart

environment:
  sdk: ">=3.5.3 <4.0.0"

dependencies:
  flutter:
    sdk: flutter

  # An abstraction for two-way communication channels based on the Dart Stream class.
  stream_channel: ^2.1.2

@redDwarf03
Copy link
Author

@kevmoo happy new year! any news about this issue please ?

@jakemac53
Copy link
Contributor

Looks like this was an accident when upgrading the package to language version 3.3, classes are no longer able to be mixed in by default. All usages of this class in this package extend the class instead of using it as a mixin, so we didn't see any errors.

I sent #1957 to fix it so it can be used as a mixin again.

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

Successfully merging a pull request may close this issue.

3 participants