2024-06-02 07:08:11 +00:00
|
|
|
import 'dart:async';
|
2024-06-01 12:18:25 +00:00
|
|
|
import 'dart:math' as math;
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:solian/providers/content/call.dart';
|
2024-06-22 15:59:11 +00:00
|
|
|
import 'package:solian/theme.dart';
|
2024-07-12 14:31:45 +00:00
|
|
|
import 'package:solian/widgets/app_bar_leading.dart';
|
2024-06-01 12:18:25 +00:00
|
|
|
import 'package:solian/widgets/chat/call/call_controls.dart';
|
|
|
|
import 'package:solian/widgets/chat/call/call_participant.dart';
|
|
|
|
|
|
|
|
class CallScreen extends StatefulWidget {
|
|
|
|
const CallScreen({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<CallScreen> createState() => _CallScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CallScreenState extends State<CallScreen> {
|
2024-06-02 07:43:42 +00:00
|
|
|
Timer? timer;
|
|
|
|
String currentDuration = '00:00:00';
|
|
|
|
|
2024-06-02 07:08:11 +00:00
|
|
|
String parseDuration() {
|
|
|
|
final ChatCallProvider provider = Get.find();
|
|
|
|
if (provider.current.value == null) return '00:00:00';
|
|
|
|
Duration duration =
|
|
|
|
DateTime.now().difference(provider.current.value!.createdAt);
|
|
|
|
|
|
|
|
String twoDigits(int n) => n.toString().padLeft(2, '0');
|
2024-06-23 10:51:49 +00:00
|
|
|
String formattedTime = '${twoDigits(duration.inHours)}:'
|
|
|
|
'${twoDigits(duration.inMinutes.remainder(60))}:'
|
|
|
|
'${twoDigits(duration.inSeconds.remainder(60))}';
|
2024-06-02 07:08:11 +00:00
|
|
|
|
|
|
|
return formattedTime;
|
|
|
|
}
|
|
|
|
|
2024-06-02 07:43:42 +00:00
|
|
|
void updateDuration() {
|
|
|
|
setState(() {
|
|
|
|
currentDuration = parseDuration();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-01 12:18:25 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
Get.find<ChatCallProvider>().setupRoom();
|
|
|
|
super.initState();
|
2024-06-02 07:43:42 +00:00
|
|
|
|
|
|
|
timer = Timer.periodic(const Duration(seconds: 1), (_) => updateDuration());
|
2024-06-01 12:18:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final ChatCallProvider provider = Get.find();
|
|
|
|
|
|
|
|
return Material(
|
|
|
|
color: Theme.of(context).colorScheme.surface,
|
2024-06-02 07:08:11 +00:00
|
|
|
child: Scaffold(
|
|
|
|
appBar: AppBar(
|
2024-07-12 14:31:45 +00:00
|
|
|
leading: const AppBarLeadingButton(),
|
2024-06-23 12:18:55 +00:00
|
|
|
centerTitle: true,
|
2024-06-22 15:59:11 +00:00
|
|
|
toolbarHeight: SolianTheme.toolbarHeight(context),
|
2024-06-02 07:08:11 +00:00
|
|
|
title: RichText(
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
text: TextSpan(children: [
|
|
|
|
TextSpan(
|
|
|
|
text: 'call'.tr,
|
|
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
|
|
),
|
2024-06-23 10:51:49 +00:00
|
|
|
const TextSpan(text: '\n'),
|
2024-06-02 07:08:11 +00:00
|
|
|
TextSpan(
|
2024-06-02 07:43:42 +00:00
|
|
|
text: currentDuration,
|
2024-06-02 07:08:11 +00:00
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
2024-06-01 12:18:25 +00:00
|
|
|
),
|
2024-06-02 07:08:11 +00:00
|
|
|
]),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
body: SafeArea(
|
|
|
|
child: Obx(
|
|
|
|
() => Stack(
|
|
|
|
children: [
|
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
color: Theme.of(context).colorScheme.surfaceContainer,
|
|
|
|
child: provider.focusTrack.value != null
|
|
|
|
? InteractiveParticipantWidget(
|
|
|
|
isFixed: false,
|
|
|
|
participant: provider.focusTrack.value!,
|
|
|
|
onTap: () {},
|
|
|
|
)
|
|
|
|
: const SizedBox(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (provider.room.localParticipant != null)
|
|
|
|
ControlsWidget(
|
|
|
|
provider.room,
|
|
|
|
provider.room.localParticipant!,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Positioned(
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
top: 0,
|
|
|
|
child: SizedBox(
|
|
|
|
height: 128,
|
|
|
|
child: ListView.builder(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
itemCount: math.max(0, provider.participantTracks.length),
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
final track = provider.participantTracks[index];
|
|
|
|
if (track.participant.sid ==
|
|
|
|
provider.focusTrack.value?.participant.sid) {
|
|
|
|
return Container();
|
|
|
|
}
|
2024-06-01 12:18:25 +00:00
|
|
|
|
2024-06-02 07:08:11 +00:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8, left: 8),
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius:
|
|
|
|
const BorderRadius.all(Radius.circular(8)),
|
|
|
|
child: InteractiveParticipantWidget(
|
|
|
|
isFixed: true,
|
|
|
|
width: 120,
|
|
|
|
height: 120,
|
|
|
|
color: Theme.of(context).cardColor,
|
|
|
|
participant: track,
|
|
|
|
onTap: () {
|
|
|
|
if (track.participant.sid !=
|
|
|
|
provider
|
|
|
|
.focusTrack.value?.participant.sid) {
|
|
|
|
provider.changeFocusTrack(track);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2024-06-01 12:18:25 +00:00
|
|
|
),
|
2024-06-02 07:08:11 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2024-06-01 12:18:25 +00:00
|
|
|
),
|
|
|
|
),
|
2024-06-02 07:08:11 +00:00
|
|
|
],
|
|
|
|
),
|
2024-06-01 12:18:25 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-06-02 07:43:42 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void deactivate() {
|
|
|
|
timer?.cancel();
|
|
|
|
timer = null;
|
|
|
|
super.deactivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void activate() {
|
|
|
|
timer ??= Timer.periodic(
|
|
|
|
const Duration(seconds: 1),
|
|
|
|
(_) => updateDuration(),
|
|
|
|
);
|
|
|
|
super.activate();
|
|
|
|
}
|
2024-06-01 12:18:25 +00:00
|
|
|
}
|