Check this
UI Display camera with duration

@override
void initState() {
super.initState();
_stopwatch = Stopwatch();
}
body: Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.black,
border: Border.all(
color:
controller != null && controller!.value.isRecordingVideo
? Colors.redAccent
: Colors.grey,
width: 3.0,
),
),
child: Padding(
padding: const EdgeInsets.all(1.0),
child: Stack(
children: [
Center(
child: _cameraPreviewWidget(),
),
Align(
alignment: Alignment.bottomLeft,
child: Text(formatTime(_stopwatch.elapsedMilliseconds), style: TextStyle(fontSize: 48.0,color: Colors.red))),
],
),
),
),
),
add timer function when the video started or Paused time
late Stopwatch _stopwatch;
void handleStartStop() {
if (_stopwatch.isRunning) {
_stopwatch.stop();
} else {
_stopwatch.start();
// _stopwatch.reset();
}
setState(() {}); // re-render the page
}
reset timer when video stoped call this function
void timerReset() {
if (_stopwatch.isRunning) {
setState(() {
_stopwatch.reset();
});
}
}
// Start video
void onVideoRecordButtonPressed() {
startVideoRecording().then((value) {
handleStartStop();
if (mounted) {
setState(() {
});
}
});
}
// Resume video
void onResumeButtonPressed() {
resumeVideoRecording().then((_) {
handleStartStop();
if (mounted) {
setState(() {});
}
showInSnackBar('Video recording resumed');
});
}
// stop video func
void onStopButtonPressed() {
stopVideoRecording().then((XFile? file) {
timerReset();
if (mounted) {
setState(() {});
}
if (file != null) {
showInSnackBar('Video recorded to ${file.path}');
videoFile = file;
_startVideoPlayer();
}
});
}