open method

Future<void> open()

Implementation

Future<void> open() async {
  final window = html.window.open(uri.toString(), title, options);
  StreamSubscription<html.MessageEvent>? subscription;
  var skipEvent = false;
  if (onMessage != null) {
    subscription = html.window.onMessage.listen((event) {
      onMessage?.call(event, () {
        skipEvent = true;
        // it might be actually null, need to implement with dart:html and not universal_html
        // ignore: invalid_null_aware_operator
        window?.close();
      });
    });
  }
  await waitForClose(window);
  await subscription?.cancel();
  if (!skipEvent) {
    onClosed();
  }
}