fix: remote video not showing — Room ChangeNotifier not listened to

_RemoteVideoView and _LocalVideoPip watched the Riverpod provider but
not the LiveKit Room's ChangeNotifier. When a remote participant joined
or published a track, notifyListeners() fired but no widget rebuilt.

Fix: wrap both views in ListenableBuilder(listenable: room) so they
rebuild on every Room event (participant connect, track subscribe, etc).

Added _AudioOnlyPlaceholder for when remote has audio but no video.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-03 06:47:53 +10:00
parent 962c833142
commit d60edcf45f

View File

@@ -1,4 +1,4 @@
// Version: 1.2.1 | Created: 2026-04-01 | Updated: 2026-04-03 // Version: 1.3.0 | Created: 2026-04-01 | Updated: 2026-04-03
// Full call screen with LiveKit video/audio. // Full call screen with LiveKit video/audio.
// - Remote video: full screen background // - Remote video: full screen background
// - Local video: picture-in-picture overlay (bottom right) // - Local video: picture-in-picture overlay (bottom right)
@@ -107,6 +107,8 @@ class _CallScreenState extends ConsumerState<CallScreen> {
// Remote video view // Remote video view
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/// Listens to the LiveKit Room's ChangeNotifier so it rebuilds when
/// remote participants join/leave or publish/unpublish tracks.
class _RemoteVideoView extends ConsumerWidget { class _RemoteVideoView extends ConsumerWidget {
const _RemoteVideoView(); const _RemoteVideoView();
@@ -117,24 +119,29 @@ class _RemoteVideoView extends ConsumerWidget {
return const _NoVideoPlaceholder(); return const _NoVideoPlaceholder();
} }
// Room extends ChangeNotifier — rebuilds on every participant/track event.
return ListenableBuilder(
listenable: room,
builder: (context, _) {
final remoteParticipants = room.remoteParticipants.values.toList(); final remoteParticipants = room.remoteParticipants.values.toList();
if (remoteParticipants.isEmpty) { if (remoteParticipants.isEmpty) {
return const _NoVideoPlaceholder(); return const _NoVideoPlaceholder();
} }
// Show the first remote participant's first video track.
final firstParticipant = remoteParticipants.first; final firstParticipant = remoteParticipants.first;
final videoPubs = firstParticipant.videoTrackPublications; final videoPubs = firstParticipant.videoTrackPublications;
if (videoPubs.isEmpty || videoPubs.first.track == null) { if (videoPubs.isEmpty || videoPubs.first.track == null) {
return const _NoVideoPlaceholder(); // Participant joined but no video track yet — show audio indicator.
return _AudioOnlyPlaceholder(name: firstParticipant.identity);
} }
// safe: checked non-null above
final videoTrack = videoPubs.first.track!; final videoTrack = videoPubs.first.track!;
return VideoTrackRenderer( return VideoTrackRenderer(
videoTrack, videoTrack,
fit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover, fit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover,
); );
},
);
} }
} }
@@ -148,7 +155,12 @@ class _LocalVideoPip extends ConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final room = ref.watch(liveKitServiceProvider).activeRoom; final room = ref.watch(liveKitServiceProvider).activeRoom;
final local = room?.localParticipant; if (room == null) return const SizedBox.shrink();
return ListenableBuilder(
listenable: room,
builder: (context, _) {
final local = room.localParticipant;
if (local == null) return const SizedBox.shrink(); if (local == null) return const SizedBox.shrink();
final videoPubs = local.videoTrackPublications; final videoPubs = local.videoTrackPublications;
@@ -156,7 +168,6 @@ class _LocalVideoPip extends ConsumerWidget {
return const SizedBox.shrink(); return const SizedBox.shrink();
} }
// safe: checked non-null above
final localTrack = videoPubs.first.track!; final localTrack = videoPubs.first.track!;
return Positioned( return Positioned(
right: 16, right: 16,
@@ -175,6 +186,8 @@ class _LocalVideoPip extends ConsumerWidget {
), ),
), ),
); );
},
);
} }
} }
@@ -182,6 +195,39 @@ class _LocalVideoPip extends ConsumerWidget {
// Placeholders and overlays // Placeholders and overlays
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
class _AudioOnlyPlaceholder extends StatelessWidget {
const _AudioOnlyPlaceholder({required this.name});
final String name;
@override
Widget build(BuildContext context) {
final initials = name.isNotEmpty ? name[0].toUpperCase() : '?';
return Container(
color: const Color(0xFF1A1A2E),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircleAvatar(
radius: 48,
backgroundColor: const Color(0xFF5C35C9),
child: Text(initials,
style: const TextStyle(fontSize: 36, color: Colors.white)),
),
const SizedBox(height: 16),
Text(name,
style: const TextStyle(color: Colors.white, fontSize: 18)),
const SizedBox(height: 8),
Text('Audio only',
style: TextStyle(
color: Colors.white.withAlpha(153), fontSize: 14)),
],
),
),
);
}
}
class _NoVideoPlaceholder extends StatelessWidget { class _NoVideoPlaceholder extends StatelessWidget {
const _NoVideoPlaceholder(); const _NoVideoPlaceholder();