🐛 Fix call lagging issue
This commit is contained in:
parent
16844294e1
commit
eb82f35a34
@ -16,6 +16,9 @@ class CallScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _CallScreenState extends State<CallScreen> {
|
||||
Timer? timer;
|
||||
String currentDuration = '00:00:00';
|
||||
|
||||
String parseDuration() {
|
||||
final ChatCallProvider provider = Get.find();
|
||||
if (provider.current.value == null) return '00:00:00';
|
||||
@ -27,17 +30,21 @@ class _CallScreenState extends State<CallScreen> {
|
||||
"${twoDigits(duration.inMinutes.remainder(60))}:"
|
||||
"${twoDigits(duration.inSeconds.remainder(60))}";
|
||||
|
||||
Timer.periodic(const Duration(seconds: 1), (_) {
|
||||
setState(() {});
|
||||
});
|
||||
|
||||
return formattedTime;
|
||||
}
|
||||
|
||||
void updateDuration() {
|
||||
setState(() {
|
||||
currentDuration = parseDuration();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
Get.find<ChatCallProvider>().setupRoom();
|
||||
super.initState();
|
||||
|
||||
timer = Timer.periodic(const Duration(seconds: 1), (_) => updateDuration());
|
||||
}
|
||||
|
||||
@override
|
||||
@ -57,7 +64,7 @@ class _CallScreenState extends State<CallScreen> {
|
||||
),
|
||||
const TextSpan(text: "\n"),
|
||||
TextSpan(
|
||||
text: parseDuration(),
|
||||
text: currentDuration,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
]),
|
||||
@ -137,4 +144,20 @@ class _CallScreenState extends State<CallScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void deactivate() {
|
||||
timer?.cancel();
|
||||
timer = null;
|
||||
super.deactivate();
|
||||
}
|
||||
|
||||
@override
|
||||
void activate() {
|
||||
timer ??= Timer.periodic(
|
||||
const Duration(seconds: 1),
|
||||
(_) => updateDuration(),
|
||||
);
|
||||
super.activate();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user