Matthias Nott
2026-03-22 ff79b0c15a045a1b3219dc179f684bf29b119a1c
lib/screens/chat_screen.dart
....@@ -480,14 +480,21 @@
480480 _scrollToBottom();
481481 }
482482
483
+ String? _recordingSessionId; // Capture session at recording start
484
+
483485 Future<void> _startRecording() async {
486
+ _recordingSessionId = ref.read(activeSessionIdProvider);
484487 final path = await AudioService.startRecording();
485488 if (path != null) {
486489 setState(() => _isRecording = true);
490
+ } else {
491
+ _recordingSessionId = null;
487492 }
488493 }
489494
490495 Future<void> _stopRecording() async {
496
+ final targetSession = _recordingSessionId;
497
+ _recordingSessionId = null;
491498 final path = await AudioService.stopRecording();
492499 setState(() => _isRecording = false);
493500
....@@ -512,7 +519,7 @@
512519 'audioBase64': b64,
513520 'content': '',
514521 'messageId': message.id,
515
- 'sessionId': ref.read(activeSessionIdProvider),
522
+ 'sessionId': targetSession,
516523 });
517524
518525 _scrollToBottom();
....@@ -551,12 +558,17 @@
551558 if (message.audioUri == null) return;
552559
553560 // Toggle: if this message is already playing, stop it
554
- if (_playingMessageId == message.id && AudioService.isPlaying) {
561
+ if (_playingMessageId == message.id) {
555562 AudioService.stopPlayback();
556563 setState(() => _playingMessageId = null);
557564 return;
558565 }
559566
567
+ // Stop any current playback first
568
+ if (_playingMessageId != null) {
569
+ AudioService.stopPlayback();
570
+ }
571
+
560572 setState(() => _playingMessageId = message.id);
561573
562574 if (message.audioUri!.startsWith('/')) {