Reputation: 2902
I am using Agora to set up Audio and Video calling. I want to display the calling time after the call is answered.
Agora offers a callback with the call duration:
rtcStats: (stats) {
print('stats');
print(stats.cpuAppUsage);
print(stats.totalDuration);
setState(() {
duration = Duration(seconds: stats.totalDuration!);
});
},
Rather than using the setState as above, that will basically be rebuilding the widget every second, what options do I have here?
Upvotes: 1
Views: 82
Reputation: 597
use valueNotifier like this
ValueNotifier<double?> secondsNotifier = ValueNotifier(null)
and double become like this
rtcStats: (stats) {
print('stats');
print(stats.cpuAppUsage);
print(stats.totalDuration);
secondNotifier.value = stats.totalDuration
},
in build add ValueListenableBuilder<double> (
valueListenable:secondNotifier,
build:(ctx,second,_){
if(second == null){
return SizedBox.shrink();
}
return Text("$second");
}
)
Upvotes: 1