onStateChanged method
Listen to recorder states RecordState.
Provides pause, resume and stop states.
Also, you can retrieve async errors from it by adding Function? onError.
Implementation
Stream<RecordState> onStateChanged() {
if (_stateStreamCtrl == null) {
_stateStreamCtrl = StreamController<RecordState>.broadcast();
_safeCall(
() async {
final stream = _platform.onStateChanged(_recorderId);
_stateStreamSubscription = stream.listen(
(state) {
if (_stateStreamCtrl case final ctrl? when ctrl.hasListener) {
ctrl.add(state);
}
},
onError: (error) {
if (_stateStreamCtrl case final ctrl? when ctrl.hasListener) {
ctrl.addError(error);
}
},
);
},
);
}
return _stateStreamCtrl!.stream;
}