Pin/Unpin Participants - Flutter
In a live stream setup, you often want to control which participant is actively visible on screen — whether it’s the host, a special guest, or someone screen sharing. To manage this dynamically, the Participant
class provides two key methods:
-
pin()
– Focus on a specific participant’s camera or screen share -
unpin()
– Remove that focus and return to the default layout
This allows you to programmatically decide who gets the spotlight in your live stream layout.
pin()
​
The pin() method makes it easy to bring a host camera or screen share front and center in the broadcast layout. Once pinned, you can write the layout logic to place this host in the primary frame, e.g. fullscreen or in a highlighted position.
unpin()
​
When a host is no longer the focus (e.g. their segment is over), you can reset their pinned state using unpin(). This allows your live stream UI to revert to a default grid view or automatically promote the next speaker.
Events associated with pin/unpin​
Following callbacks are received when a host is pinned or unpinned in the livestream.
- This event will be emitted when any participant pin state gets changed.
- It will pass
participantId
,state
, andpinnedBy
asMap<String, dynamic>
as an event handler parameter.
import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';
class SpeakerScreen extends StatefulWidget {
...
}
class _SpeakerScreenState extends State<SpeakerScreen> {
late Room room;
Map<String, Participant> _attendees = {};
@override
void initState() {
setupLiveStreamEventListners();
...
}
void setUpLiveStreamEventListners(){
room.on(Events.pinStateChanged, (data) {
// do something
});
}
@override
Widget build(BuildContext context) {
return Column(
children:[
...
]
);
}
void updateAttendees(){
Map<String, Participant> attendees = {};
//we will pin localparticiant if mode is SEND_AND_RECV
if(room.localParticipant.mode == Mode.SIGNALLING_ONLY);{
attendees.putIfAbsent(
room.localParticipant.id, () => room.localParticipant);
room.localParticipant.unpin();
}else{
room.localParticipant.pin();
}
room.participants.values.forEach((participant) {
if (participant.mode == Mode.SIGNALLING_ONLY) {
attendees.putIfAbsent(participant.id, () => participant);
participant.unpin();
}
});
setState(()=>_attendees = attendees);
}
}
API Reference​
The API references for all the methods utilized in this guide are provided below.
Got a Question? Ask us on discord