Skip to main content
Version: 3.x.x

RealtimeStore Methods - Flutter

setValue()

The setValue() method is used to store or update data in the RealtimeStore. If a key already exists, it will be overwritten with the new value. Passing null as the value deletes the key.

Key Notes

  • Supports String values only.
  • Each key can store up to 1 KB of data.
  • A maximum of 100 keys are allowed per session.
  • Deletion is performed by setting the value to null.
  • Throws an error if:
    • The key is missing or empty.
    • The request fails.
    • The session exceeds the 100-key limit.

Parameters

  • key (String)
    The unique key to store the data under.

  • value (String?)
    The string value to be stored. Pass null to delete the key.

Returns

  • Future<void>

Example

import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class MeetingScreen extends StatefulWidget {
//Existing configuration
}

class _MeetingScreenState extends State<MeetingScreen> {
late Room _room;

@override
void initState() {
_room = VideoSDK.createRoom(
roomId: widget.meetingId,
token: widget.token,
displayName: "User1",
micEnabled: true,
camEnabled: true,
defaultCameraIndex: 0,
multiStream: true,
mode: Mode.SEND_AND_RECV,
);
_room.join();
}

@override
Widget build(BuildContext context) {
return Column(children: [
ElevatedButton(
String key = "BLOCK_CHAT";
String value = "true";
onPressed: () async {
try{
await _room.realtimeStore.setValue(key, value);
} catch(e){
print("Error:$e");
}

},
child: const Text("Realtime Store Set Value"),
),
]);
}
}

getValue()

The getValue() method retrieves the current value associated with a given key.

Key Notes

  • Returns the current string value for the given key.
  • Useful for fetching shared state when joining a meeting or reloading a view.
  • Throws an error if the key is missing/empty or if the request fails.

Parameters

  • key (String)
    The key whose value you want to retrieve.

Returns

  • Future<String?>- The stored value or null if there was a problem fetching the value.

Example

import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class MeetingScreen extends StatefulWidget {
//Existing configuration
}

class _MeetingScreenState extends State<MeetingScreen> {
late Room _room;

@override
void initState() {
_room = VideoSDK.createRoom(
roomId: widget.meetingId,
token: widget.token,
displayName: "User1",
micEnabled: true,
camEnabled: true,
defaultCameraIndex: 0,
multiStream: true,
mode: Mode.SEND_AND_RECV,
);
_room.join();
}

@override
Widget build(BuildContext context) {
return Column(children: [
ElevatedButton(
String key = "BLOCK_CHAT";
String response= "";
onPressed: () async {
try {
response = await _room.realtimeStore.getValue(key);
} catch(e){
print("Error:$e");
}
},
child: const Text("Realtime Store Get Value:$response"),
),
]);
}
}

observe()

The observe() method subscribes to real-time updates for a given key. When the key’s value changes, a delegate method on your listener is automatically triggered for all connected participants.

Key Notes

  • Returns an observerId which you can later use to stop observing.
  • The callback receives the new value and information about who updated it.
  • Ideal for syncing live data like timers, shared notes, or agendas.

Parameters

  • key (String)
    The key to observe.

  • callback (function) Function triggered on each update. Receives:

    • value (String?) → Updated value or null if deleted
    • updatedBy (Participant?) → Object of participant who made the update

Returns

  • Future<String>

Example

import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class MeetingScreen extends StatefulWidget {
//Existing configuration
}

class _MeetingScreenState extends State<MeetingScreen> {
late Room _room;

@override
void initState() {
_room = VideoSDK.createRoom(
roomId: widget.meetingId,
token: widget.token,
displayName: "User1",
micEnabled: true,
camEnabled: true,
defaultCameraIndex: 0,
multiStream: true,
mode: Mode.SEND_AND_RECV,
);
_room.join();
}

@override
Widget build(BuildContext context) {
return Column(children: [
ElevatedButton(
String key = "BLOCK_CHAT";
onPressed: () async {
try {
observerId = await meeting.realtimeStore.observe(key,(value, updatedBy) {
// as participant can be null so kept in try catch
print("Updated by: ${updatedBy!.id}");
},
);
} catch(e){
print("Error:$e");
}
}
child: const Text("Realtime Store Observe"),
),
]);
}
}

stopObserving()

Stops receiving updates for a specific key and listener combination.

Key Notes

  • Should be called when the listener is no longer needed (e.g., component unmount).

Parameters

  • observerId (String) The observer ID returned from observe().

Returns

  • Future<void>

Example

import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class MeetingScreen extends StatefulWidget {
//Existing configuration
}

class _MeetingScreenState extends State<MeetingScreen> {
late Room _room;

@override
void initState() {
_room = VideoSDK.createRoom(
roomId: widget.meetingId,
token: widget.token,
displayName: "User1",
micEnabled: true,
camEnabled: true,
defaultCameraIndex: 0,
multiStream: true,
mode: Mode.SEND_AND_RECV,
);
_room.join();
}

@override
Widget build(BuildContext context) {
return Column(children: [
ElevatedButton(
onPressed: () async {
try{
if (observerId != null) {
await meeting.realtimeStore
.stopObserving(observerId!);
print(
"Stopped observing with ID: $observerId");
observerId = null; // Clear the observer ID
} else {
print("No active observer to stop");
}
} catch(e){
print("Error:$e");
}
Navigator.pop(context);
},
),
]);
}
}

Got a Question? Ask us on discord