#flutter #stream #stream-builder #voice-recording
Вопрос:
Я хочу визуализировать записанную интенсивность звука в моем приложении flutter с помощью flutter_sound. Я слушаю поток onProgress в будущем построителе, который должен возвращать значение в децибелах при включенной записи. Проблема в том, что поток всегда возвращает значение null!
StreamBuilder<RecordingDisposition>(
stream: _recorder!.onProgress,
builder: (context, snapshot) {
log.debug(snapshot.data);
if (!snapshot.hasData || snapshot.data == null) {
return Container(
width: 120,
color: Colors.green,
);
}
return Container(
width: 120,
child: Container(
color: Colors.red,
width: snapshot.data!.decibels,
));
}),
А вот код, которым я инициализирую в нем диктофон.
Future<void> openTheRecorder() async {
var status = await Permission.microphone.request();
if (status != PermissionStatus.granted) {
throw RecordingPermissionException('Microphone permission not granted');
}
await _recorder!.openAudioSession(
focus: AudioFocus.requestFocusAndDuckOthers,
category: SessionCategory.record,
);
this.record();
}