StreamBuilder<Duration>(
stream: call.callDurationStream,
builder: (context, snapshot) {
final duration = snapshot.data ?? Duration.zero;
final minutes = duration.inMinutes;
final seconds = duration.inSeconds.remainder(60);
final formattedDuration =
'${minutes.toString().padLeft(2, '0')}:${seconds.toString().padLeft(2, '0')}';
return Text(
formattedDuration,
style: TextStyle(color: AppColorPalette.primaryText),
);
},
)
Call Duration
The Call Duration feature allows you to display the elapsed time of an ongoing call. This is useful for users to track how long they’ve been in a call.
Using callDurationStream
The Call
class provides a callDurationStream
that emits the current duration of the call as a Duration
object. You can listen to this stream to display a timer that updates in real-time.
Here’s an example of how to create a call duration display:
This example:
- Uses a
StreamBuilder
to listen to thecallDurationStream
- Extracts minutes and seconds from the duration
- Formats the duration in a MM:SS format (minutes:seconds)
- Pads each number with leading zeros to ensure a consistent display format (e.g., “01:05” instead of “1:5”)
Customizing the Duration Display
You can customize the appearance of the call duration display by modifying the text style. You can also change the format of the duration display if you need to show hours or other time elements.