onmessage

Creator: coderz1093

Last updated:

Add to Cart

Description:

onmessage

A stream wrapping JavaScript's window.onmessage that is safe to import even on platforms
other than web.
Purpose #
In web apps, you can listen to events from other frames like this:
import 'dart:html' as html;

void main() {
html.window.onMessage.listen((html.MessageEvent event) {
// Handle.
});
// ...
}
copied to clipboard
However, dart:html is not available on platforms other than web. If you use it,
your app cannot be built there.
The Dart team recommends conditional import of files that use dart:html
which gets your app complex. And even then you must silence a linter warning of importing
dart:html in a non-web-only package.
This package provides a wrapper for that stream of messages that can be used on all platforms.
On platforms other than web, the stream would just produce no events.
Usage #
import 'package:onmessage/onmessage.dart';

void main() {
OnMessage.instance.stream.listen((MessageEvent event) {
// Handle.
});
// ...
}
copied to clipboard
MessageEvent class from this package is an independent class with fields copied from the original
html.MessageEvent. It is provided so that you can have an API independent from web.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files:

Customer Reviews

There are no reviews.