Skip to main content
Version: 1.1.x

Raise Hand - Flutter

Let us see, how we can use PubSub to implement Raise hand functionality. If you are not familiar with the PubSub mechanism you can follow this guide.

Implementing Raise Hand

  1. We will be creating a button when clicked, we will publish a message it the topic RAISE_HAND
import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class NotifyView extends StatefulWidget {
final Room room;
...
}

class _NotifyViewState extends State<NotifyView> {

final msgTextController = TextEditingController();


@override
void initState() {
...
}

@override
Widget build(BuildContext context) {
return Column(
children:[
ElevatedButton(
onPressed:(){
widget.room.pubSub
.publish(
"RAISE_HAND",
"Raised Hand",
const PubSubPublishOptions(
persist: true),
);
},
child: const Text("Raise Hand"),
),
],
);
}

}
  1. Now let us show an alert to all the speakers showing who raised the hand.
import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class SpeakerView extends StatefulWidget {
final Room room;
...
}

class _SpeakerViewState extends State<SpeakerView> {

@override
void initState() {
...

// Subscribing 'RAISE_HAND' Topic
widget.meeting.pubSub
.subscribe("RAISE_HAND", messageHandler);
}

//Handler which will be called when new mesasge is
//These is where we will show the message
void messageHandler(PubSubMessage message) {
if(context.mounted && widget.room.localParticipant.mode == Mode.CONFERENCE){
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"${message.senderName} raised hand",
overflow: TextOverflow.fade,
),
));
}
}

@override
Widget build(BuildContext context) {
return Column(
children:[
...
]
);
}

@override
void dispose() {
// Unsubscribe
widget.room.pubSub.unsubscribe("RAISE_HAND", messageHandler);
super.dispose();
}

}

API Reference

The API references for all the methods and events utilized in this guide are provided below.

Got a Question? Ask us on discord