-
Notifications
You must be signed in to change notification settings - Fork 13
/
pickup_screen.dart
193 lines (183 loc) · 6.86 KB
/
pickup_screen.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import 'dart:async';
import 'package:agoravideocall/socket/model/res_call_accept_model.dart';
import 'package:agoravideocall/socket/model/res_call_request_model.dart';
import 'package:agoravideocall/socket/socket_constants.dart';
import 'package:agoravideocall/socket/socket_manager.dart';
import 'package:agoravideocall/utils/check_network_connectivity.dart';
import 'package:agoravideocall/utils/color_utils.dart';
import 'package:agoravideocall/utils/constants/arg_constants.dart';
import 'package:agoravideocall/utils/constants/file_constants.dart';
import 'package:agoravideocall/utils/constants/route_constants.dart';
import 'package:agoravideocall/utils/dimens.dart';
import 'package:agoravideocall/utils/localization/localization.dart';
import 'package:agoravideocall/utils/navigation.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_ringtone_player/flutter_ringtone_player.dart';
import 'package:flutter_svg/svg.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:wakelock/wakelock.dart';
class PickUpScreen extends StatefulWidget {
final ResCallRequestModel? resCallRequestModel;
final ResCallAcceptModel? resCallAcceptModel;
final bool isForOutGoing;
PickUpScreen(
{this.resCallRequestModel,
this.resCallAcceptModel,
this.isForOutGoing = false});
@override
_PickUpScreenState createState() => _PickUpScreenState();
}
class _PickUpScreenState extends State<PickUpScreen> {
Timer? _timer;
@override
void initState() {
super.initState();
Wakelock.enable(); // Turn on wakelock feature till call is running
//To Play Ringtone
FlutterRingtonePlayer.play(
android: AndroidSounds.ringtone,
ios: IosSounds.electronic,
looping: true,
volume: 0.5,
asAlarm: false);
_timer = Timer(const Duration(milliseconds: 60 * 1000), _endCall);
}
@override
void dispose() {
//To Stop Ringtone
FlutterRingtonePlayer.stop();
_timer?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
getScreenSize(context);
return Scaffold(
body: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
stops: [0.1, 0.6],
colors: [ColorUtils.accentColor, ColorUtils.primaryColor],
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
widget.isForOutGoing
? Localization.of(context)!.outGoingCallTitle
: Localization.of(context)!.pickUpCallTitle,
style: TextStyle(
color: ColorUtils.whiteColor,
fontSize: headerTitleSize,
fontWeight: fontWeightRegular),
),
SizedBox(height: spacingXXXSLarge),
_getImageUrlWidget(),
SizedBox(height: spacingLarge),
Text(Localization.of(context)!.pickupScreenUserName,
style: TextStyle(
color: ColorUtils.whiteColor,
fontSize: headerTitleSize,
fontWeight: fontWeightRegular)),
SizedBox(height: spacingXXXSLarge),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_callingButtonWidget(context, false),
!widget.isForOutGoing
? _callingButtonWidget(context, true)
: SizedBox(),
],
),
],
),
),
);
}
//To Display Profile Image Of User
_getImageUrlWidget() => ClipOval(
child: CircleAvatar(
backgroundColor: ColorUtils.whiteColor,
radius: screenSize!.width * 0.2,
child: CachedNetworkImage(
fit: BoxFit.cover,
width: imageXLarge,
height: imageXLarge,
placeholder: (context, url) => Center(
child: SizedBox(
height: spacingXXMLarge,
width: spacingXXMLarge,
child: CircularProgressIndicator(
backgroundColor: ColorUtils.accentColor,
),
),
),
errorWidget: (context, url, error) => SvgPicture.asset(
FileConstants.icUserPlaceholder,
color: ColorUtils.primaryColor.withAlpha(150),
),
imageUrl: ""), // Any ImageUrl
));
//Reusable Accept & Reject Call Ui/Ux
_callingButtonWidget(BuildContext context, bool isCall) => RawMaterialButton(
onPressed: () {
if (isCall) {
_timer?.cancel();
pickUpCallPressed(context);
} else {
_endCall();
}
},
child: Icon(isCall ? Icons.call : Icons.call_end,
color: Colors.white, size: imageMTiny),
shape: CircleBorder(),
elevation: 2.0,
fillColor: isCall ? Colors.green : Colors.redAccent,
padding: const EdgeInsets.all(spacingMedium));
//Call This Method When User Pressed On Accept Call Button
void pickUpCallPressed(BuildContext context) async {
if (await Permission.camera.request().isGranted) {
if (await Permission.microphone.request().isGranted) {
FlutterRingtonePlayer.stop();
if (await checkNetworkConnection(context)) {
//Emit Accept Call Event Into Socket
emit(
SocketConstants.acceptCall,
({
ArgParams.connectId: widget.resCallRequestModel?.id,
ArgParams.channelKey: widget.resCallRequestModel?.channel,
ArgParams.channelTokenKey: widget.resCallRequestModel?.token,
}));
NavigationUtils.pushReplacement(
context, RouteConstants.routeVideoCall,
arguments: {
ArgParams.channelKey: widget.resCallRequestModel?.channel,
ArgParams.channelTokenKey: widget.resCallRequestModel?.token,
ArgParams.resCallRequestModel: widget.resCallRequestModel,
ArgParams.resCallAcceptModel: ResCallAcceptModel(),
ArgParams.isForOutGoing: widget.isForOutGoing,
});
}
}
}
}
//Call This Method When User Pressed On Reject Call Button
_endCall() async {
Wakelock.disable(); // Turn off wakelock feature after call end
FlutterRingtonePlayer.stop(); // To Stop Ringtone
//Emit Reject Call Event Into Socket
emit(
SocketConstants.rejectCall,
({
ArgParams.connectId: widget.isForOutGoing
? widget.resCallAcceptModel?.otherUserId
: widget.resCallRequestModel?.id,
}));
NavigationUtils.pop(context);
}
}