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:

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),
    );
  },
)

This example:

  1. Uses a StreamBuilder to listen to the callDurationStream
  2. Extracts minutes and seconds from the duration
  3. Formats the duration in a MM:SS format (minutes:seconds)
  4. 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.

© Getstream.io, Inc. All Rights Reserved.