Lost focus handling in Dart
How to deal with lost focus in a dart? For example, if some code is running on a page and users (for example) minimize the window or switch to another tab, the current page will lose focus. Is there some method that works in this case that I can override in my code?
+3
ViliX64
source
to share
1 answer
import 'dart:html' as dom; import 'dart:async'; void main() { dom.document.onVisibilityChange.listen(visibilityChangeHandler); dom.window.onFocus.listen(focusHandler); dom.window.onBlur.listen(blurHandler); } void visibilityChangeHandler(dom.Event e) { print('visibility changed: $e'); } void focusHandler(dom.Event e) { print('focus: $e'); } void blurHandler(dom.Event e) { print('blur: $e'); }
see also Is there a way to determine if a browser window is open?
+1
Günter Zöchbauer
source
to share