dint-dev / universal_html

Cross-platform 'dart:html'.
https://pub.dev/packages/universal_html
Apache License 2.0
200 stars 59 forks source link

BroadcastChannel is not a type. #96

Open jay-athelas opened 5 months ago

jay-athelas commented 5 months ago

I am trying to use the BroadcastChannel api , to send communication between a service worker and the main thread. Our app is hybrid, currently support web, ios and android.

Even when importing from import 'package:universal_html/html.dart'; I get a compilation error when trying to build for ios, stating that BroadastChannel is not a type. I can click on it and see the definition in html_dart2js.dart. What is going on here?

To replicate:

dab246 commented 5 months ago

You can use 1 of the following 2 ways:

  1. Use of conditional imports/exports
class BroadcastChannel {
   final String name;

   BroadcastChannel(this.name);

   Stream<dynamic> get onMessage => const Stream.empty();
}
export 'dart:html' show BroadcastChannel;
export 'broadcast_channel_stub.dart' if (dart.library.html) 'broadcast_channel_web.dart';
  1. Wait for PR #97 to be merged for use.
jay-athelas commented 5 months ago

Thanks @dab246 , awesome, do you have an estimate of when this PR might be merged?