onWindowFocus property
Returns a stream broadcasting the browser's window focus changes.
Implementation
static Stream<bool> get onWindowFocus {
StreamController<bool>? controller;
// Event listener reacting on mouse enter events.
void enterListener(web.Event event) => controller!.add(true);
// Event listener reacting on mouse leave events.
void leaveListener(web.Event event) => controller!.add(false);
controller = StreamController(
onListen: () {
web.document.addEventListener('mouseenter', enterListener.toJS);
web.document.addEventListener('mouseleave', leaveListener.toJS);
},
onCancel: () {
web.document.removeEventListener('mouseenter', enterListener.toJS);
web.document.removeEventListener('mouseleave', leaveListener.toJS);
},
);
return controller.stream;
}