Skip to content

Commit c5fd74e

Browse files
committed
Use stable reference for JS listener.
1 parent 1322082 commit c5fd74e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

sdk/@launchdarkly/launchdarkly_flutter_observability/lib/src/instrumentation/lifecycle/platform/js_lifecycle_listener.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ class LDAppLifecycleListener {
1818
: AppLifecycleState.resumed,
1919
);
2020

21+
/// Use a stable reference for the JS listener.
22+
final listenerJS = listenerFunc.toJS;
23+
2124
_streamController.onListen = () {
22-
web.document.addEventListener('visibilitychange', listenerFunc.toJS);
25+
web.document.addEventListener('visibilitychange', listenerJS);
2326
};
2427

2528
_streamController.onCancel = () {
26-
web.document.removeEventListener('visibilitychange', listenerFunc.toJS);
29+
web.document.removeEventListener('visibilitychange', listenerJS);
2730
};
2831
}
2932

0 commit comments

Comments
 (0)