-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathui_call_screen.dart
More file actions
189 lines (175 loc) · 5.69 KB
/
ui_call_screen.dart
File metadata and controls
189 lines (175 loc) · 5.69 KB
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
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:twilio_voice/_internal/js/core/enums/device_sound_name.dart';
import 'package:twilio_voice/twilio_voice.dart';
import 'ui_permissions_screen.dart';
import 'widgets/call_actions.dart';
import 'widgets/call_features.dart';
import 'widgets/call_status.dart';
import 'widgets/twilio_log.dart';
typedef PerformCall = Future<void> Function(String clientIdentifier);
class UICallScreen extends StatefulWidget {
final String userId;
final PerformCall onPerformCall;
final PerformCall? onCallToQueue;
const UICallScreen({Key? key, required this.userId, required this.onPerformCall, this.onCallToQueue}) : super(key: key);
@override
State<UICallScreen> createState() => _UICallScreenState();
}
class _UICallScreenState extends State<UICallScreen> {
late TextEditingController _controller;
late final GlobalKey<FormFieldState<String>> _identifierKey = GlobalKey<FormFieldState<String>>();
bool _copied = false;
String _getRecipientIdFromEnv() {
return const String.fromEnvironment("RECIPIENT_ID");
}
@override
void initState() {
super.initState();
_controller = TextEditingController(text: _getRecipientIdFromEnv());
}
void _copyToClipboard(String data) {
Clipboard.setData(ClipboardData(text: data));
setState(() {
_copied = true;
});
Future.delayed(const Duration(seconds: 1), () {
setState(() {
_copied = false;
});
});
}
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
TextFormField(
key: _identifierKey,
controller: _controller,
validator: (value) {
if (value == null || value.isEmpty) {
return "Please enter a client identifier";
}
return null;
},
decoration: const InputDecoration(labelText: 'Client Identifier or Phone Number'),
),
const SizedBox(height: 10),
Wrap(
children: [
Text("My Identity: ${widget.userId}"),
const SizedBox(width: 8),
GestureDetector(
onTap: () => _copyToClipboard(widget.userId),
child: _copied ? const Icon(Icons.check, color: Colors.green, size: 16) : const Icon(Icons.copy, size: 16),
),
],
),
const SizedBox(height: 10),
CallActions(
canCall: true,
onPerformCall: () {
final identifier = _identifierKey.currentState?.value;
if (identifier != null && identifier.isNotEmpty) {
widget.onPerformCall(identifier);
}
},
),
const SizedBox(height: 10),
const Card(
child: Padding(
padding: EdgeInsets.all(8.0),
child: CallStatus(),
),
),
const Card(
child: Padding(
padding: EdgeInsets.all(8.0),
child: CallControls(),
),
),
ListTile(
title: const Text("Permissions"),
subtitle: const Text("Please allow all permissions to use the app"),
trailing: const Icon(Icons.arrow_forward_ios),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const UiPermissionsScreen(),
),
);
},
),
const Divider(),
const _RingSound(),
const Divider(),
Expanded(
child: Column(
children: [
Text("Events (latest at top)", style: Theme.of(context).textTheme.titleLarge),
const TwilioLog(),
],
),
),
],
);
}
}
class _RingSound extends StatefulWidget {
const _RingSound({Key? key}) : super(key: key);
@override
State<_RingSound> createState() => _RingSoundState();
}
class _RingSoundState extends State<_RingSound> {
final _tv = TwilioVoicePlatform.instance;
final TextEditingController _controller = TextEditingController();
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
child: TextFormField(
controller: _controller,
decoration: InputDecoration(
labelText: "Enter custom url sound (mp3)",
hintText: "https://sdk.twilio.com/js/client/sounds/releases/1.0.0/incoming.mp3",
suffix: IconButton(
icon: const Icon(Icons.clear),
onPressed: () {
_controller.clear();
},
),
),
),
),
const SizedBox(width: 8),
ElevatedButton(
onPressed: () async {
final url = _controller.text.isEmpty ? null : _controller.text;
await _tv.updateSound(SoundName.Incoming, url);
// ignore: use_build_context_synchronously
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Updated incoming sound to ${_controller.text}")),
);
},
child: const Text("Update"),
),
const SizedBox(width: 4),
ElevatedButton(
onPressed: () async {
await _tv.updateSound(SoundName.Incoming, null);
// ignore: use_build_context_synchronously
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Reset incoming sound")),
);
},
child: const Text("Reset"),
),
],
),
);
}
}