onStorageChange property
Returns a stream broadcasting the browser's storage changes.
Implementation
static Stream<WebStorageEvent> get onStorageChange {
StreamController<WebStorageEvent>? controller;
// Event listener reacting on storage changes.
void storageListener(web.Event event) {
event as web.StorageEvent;
controller!.add(
WebStorageEvent(
key: event.key,
newValue: event.newValue,
oldValue: event.oldValue,
),
);
}
controller = StreamController(
onListen:
() => web.window.addEventListener('storage', storageListener.toJS),
onCancel:
() => web.window.removeEventListener('storage', storageListener.toJS),
);
return controller.stream;
}