onThreatDetected property
Returns a broadcast stream. When security is compromised onThreatDetected receives what type of Threat caused it.
To receive updates about threats, listen to the stream:
final subscription = Talsec.instance.onThreatDetected.listen((threat) {
// Handle threat
});
When you're finished listening for threats, don't forget to cancel stream:
subscription.cancel();
Implementation note:
onThreatDetected is internally used by attachListener which turns stream events into function callbacks. While onThreatDetected is a broadcast stream (and hence can have a multiple receivers) it is not recommended to use both approaches at the same time.
Implementation
Stream<Threat> get onThreatDetected {
if (_onThreatDetected != null) {
return _onThreatDetected!;
}
_onThreatDetected = eventChannel
.receiveBroadcastStream()
.cast<int>()
.map(ThreatX.fromInt)
.handleError(_handleStreamError);
return _onThreatDetected!;
}