Skip to content

Commit 49dab9b

Browse files
committed
refactor: linter
1 parent 4ea41be commit 49dab9b

File tree

15 files changed

+172
-161
lines changed

15 files changed

+172
-161
lines changed

example/lib/api.dart

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import 'package:http/http.dart' as http;
44

55
import 'package:cloud_functions/cloud_functions.dart';
66

7+
import 'utils.dart';
8+
79
class Result {
810
final String identity;
911
final String accessToken;
@@ -20,23 +22,23 @@ class Result {
2022
/// "token": "ey...",
2123
/// }
2224
Future<Result?> generateLocalAccessToken() async {
23-
print("voip-registering with token ");
24-
print("GET http://localhost:3000/token");
25+
printDebug("voip-registering with token ");
26+
printDebug("GET http://localhost:3000/token");
2527

2628
final uri = Uri.http("localhost:3000", "/token");
2729
final result = await http.get(uri);
2830
if (result.statusCode >= 200 && result.statusCode < 300) {
29-
print("Error requesting token from server [${uri.toString()}]");
30-
print(result.body);
31+
printDebug("Error requesting token from server [${uri.toString()}]");
32+
printDebug(result.body);
3133
return null;
3234
}
3335
final data = jsonDecode(result.body);
3436
final identity = data["identity"] as String?;
3537
final token = data["token"] as String?;
3638

3739
if (identity == null || token == null) {
38-
print("Error requesting token from server [${uri.toString()}]");
39-
print(result.body);
40+
printDebug("Error requesting token from server [${uri.toString()}]");
41+
printDebug(result.body);
4042
return null;
4143
}
4244
return Result(identity, token);
@@ -51,8 +53,8 @@ Future<Result?> generateLocalAccessToken() async {
5153
/// }
5254
///
5355
Future<Result?> generateFirebaseAccessToken() async {
54-
print("voip-registtering with token ");
55-
print("voip-calling voice-accessToken");
56+
printDebug("voip-registtering with token ");
57+
printDebug("voip-calling voice-accessToken");
5658
final function = FirebaseFunctions.instance.httpsCallable("voice-accessToken");
5759

5860
final params = {
@@ -67,8 +69,8 @@ Future<Result?> generateFirebaseAccessToken() async {
6769
final token = data["token"] as String?;
6870

6971
if (identity == null || token == null) {
70-
print("Error requesting token from server [${function.toString()}]");
71-
print(result.data);
72+
printDebug("Error requesting token from server [${function.toString()}]");
73+
printDebug(result.data);
7274
return null;
7375
}
7476
return Result(identity, token);

example/lib/main.dart

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:twilio_voice_example/screens/ui_call_screen.dart';
1111
import 'package:twilio_voice_example/screens/ui_registration_screen.dart';
1212

1313
import 'api.dart';
14+
import 'utils.dart';
1415

1516
extension IterableExtension<E> on Iterable<E> {
1617
/// Extension on [Iterable]'s [firstWhere] that returns null if no element is found instead of throwing an exception.
@@ -42,7 +43,7 @@ void main() async {
4243
WidgetsFlutterBinding.ensureInitialized();
4344
if (kIsWeb) {
4445
// Add firebase config here
45-
final options = const FirebaseOptions(
46+
const options = FirebaseOptions(
4647
apiKey: '',
4748
appId: '',
4849
messagingSenderId: '',
@@ -86,7 +87,7 @@ class _AppState extends State<App> {
8687

8788
//#region #region Register with Twilio
8889
void register() async {
89-
print("voip-service registration");
90+
printDebug("voip-service registration");
9091

9192
// Use for locally provided token generator e.g. Twilio's quickstarter project: https://github.com/twilio/voice-quickstart-server-node
9293
if (!kIsWeb) {
@@ -116,12 +117,12 @@ class _AppState extends State<App> {
116117

117118
/// Registers [accessToken] with TwilioVoice plugin, acquires a device token from FirebaseMessaging and registers with TwilioVoice plugin.
118119
Future<bool> _registerAccessToken(String accessToken) async {
119-
print("voip-registering access token");
120+
printDebug("voip-registering access token");
120121

121122
String? androidToken;
122123
if (Platform.isAndroid || kIsWeb) {
123124
androidToken = await FirebaseMessaging.instance.getToken();
124-
print("androidToken is " + androidToken!);
125+
printDebug("androidToken is ${androidToken!}");
125126
}
126127
final result = await TwilioVoice.instance.setTokens(accessToken: accessToken, deviceToken: androidToken);
127128
return result ?? false;
@@ -141,9 +142,9 @@ class _AppState extends State<App> {
141142
if (myId.isEmpty) myId = null;
142143
if (myToken.isEmpty) myToken = null;
143144

144-
print("voip-registering with environment variables");
145+
printDebug("voip-registering with environment variables");
145146
if (myId == null || myToken == null) {
146-
print("Failed to register with environment variables, please provide ID and TOKEN");
147+
printDebug("Failed to register with environment variables, please provide ID and TOKEN");
147148
return false;
148149
}
149150
userId = myId;
@@ -165,10 +166,10 @@ class _AppState extends State<App> {
165166
/// Use this method to register with a local token generator
166167
/// To access this, run with `--dart-define=REGISTRATION_METHOD=local`
167168
Future<bool> _registerLocal() async {
168-
print("voip-registering with local token generator");
169+
printDebug("voip-registering with local token generator");
169170
final result = await generateLocalAccessToken();
170171
if (result == null) {
171-
print("Failed to register with local token generator");
172+
printDebug("Failed to register with local token generator");
172173
return false;
173174
}
174175
userId = result.identity;
@@ -181,9 +182,9 @@ class _AppState extends State<App> {
181182
void _listenForFirebaseLogin() {
182183
final auth = FirebaseAuth.instance;
183184
auth.authStateChanges().listen((user) async {
184-
// print("authStateChanges $user");
185+
// printDebug("authStateChanges $user");
185186
if (user == null) {
186-
print("user is anonomous");
187+
printDebug("user is anonomous");
187188
await auth.signInAnonymously();
188189
} else if (!authRegistered) {
189190
authRegistered = true;
@@ -192,7 +193,7 @@ class _AppState extends State<App> {
192193
if (userId.isEmpty) {
193194
userId = user.uid;
194195
}
195-
print("registering client $userId [firebase id ${user.uid}]");
196+
printDebug("registering client $userId [firebase id ${user.uid}]");
196197
_registerFirebase();
197198
}
198199
});
@@ -205,10 +206,10 @@ class _AppState extends State<App> {
205206
_listenForFirebaseLogin();
206207
return false;
207208
}
208-
print("voip-registering with firebase token generator");
209+
printDebug("voip-registering with firebase token generator");
209210
final result = await generateFirebaseAccessToken();
210211
if (result == null) {
211-
print("Failed to register with firebase token generator");
212+
printDebug("Failed to register with firebase token generator");
212213
return false;
213214
}
214215
userId = result.identity;
@@ -224,7 +225,7 @@ class _AppState extends State<App> {
224225
super.initState();
225226

226227
TwilioVoice.instance.setOnDeviceTokenChanged((token) {
227-
print("voip-device token changed");
228+
printDebug("voip-device token changed");
228229
if (!kIsWeb) {
229230
register();
230231
}
@@ -233,7 +234,7 @@ class _AppState extends State<App> {
233234
listenForEvents();
234235
register();
235236

236-
final partnerId = "alicesId";
237+
const partnerId = "alicesId";
237238
TwilioVoice.instance.registerClient(partnerId, "Alice");
238239
// TwilioVoice.instance.requestReadPhoneStatePermission();
239240
// TwilioVoice.instance.requestMicAccess();
@@ -243,7 +244,7 @@ class _AppState extends State<App> {
243244
/// Listen for call events
244245
void listenForEvents() {
245246
TwilioVoice.instance.callEventsListener.listen((event) {
246-
print("voip-onCallStateChanged $event");
247+
printDebug("voip-onCallStateChanged $event");
247248

248249
switch (event) {
249250
case CallEvent.incoming:
@@ -260,7 +261,7 @@ class _AppState extends State<App> {
260261
if (activeCall != null) {
261262
final customData = activeCall.customParams;
262263
if (customData != null) {
263-
print("voip-customData $customData");
264+
printDebug("voip-customData $customData");
264265
}
265266
}
266267
break;
@@ -285,11 +286,11 @@ class _AppState extends State<App> {
285286
/// Place a call to [clientIdentifier]
286287
Future<void> _onPerformCall(String clientIdentifier) async {
287288
if (!await (TwilioVoice.instance.hasMicAccess())) {
288-
print("request mic access");
289+
printDebug("request mic access");
289290
TwilioVoice.instance.requestMicAccess();
290291
return;
291292
}
292-
print("starting call to $clientIdentifier");
293+
printDebug("starting call to $clientIdentifier");
293294
TwilioVoice.instance.call.place(to: clientIdentifier, from: userId, extraOptions: {"_TWI_SUBJECT": "Company Name"});
294295
}
295296

@@ -341,19 +342,19 @@ class _AppState extends State<App> {
341342
final activeCall = TwilioVoice.instance.call.activeCall!;
342343
final action = await showIncomingCallScreen(context, activeCall);
343344
if (action == true) {
344-
print("accepting call");
345+
printDebug("accepting call");
345346
TwilioVoice.instance.call.answer();
346347
} else if (action == false) {
347-
print("rejecting call");
348+
printDebug("rejecting call");
348349
TwilioVoice.instance.call.hangUp();
349350
} else {
350-
print("no action");
351+
printDebug("no action");
351352
}
352353
}
353354

354355
Future<bool?> showIncomingCallScreen(BuildContext context, ActiveCall activeCall) async {
355356
if (!kIsWeb && !Platform.isAndroid) {
356-
print("showIncomingCallScreen only for web");
357+
printDebug("showIncomingCallScreen only for web");
357358
return false;
358359
}
359360

example/lib/screens/widgets/on_call_widget.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class _CallSID extends StatelessWidget {
116116
class _StatusIcon extends StatelessWidget {
117117
final bool active;
118118

119-
const _StatusIcon({super.key, required this.active});
119+
const _StatusIcon({required this.active});
120120

121121
@override
122122
Widget build(BuildContext context) {

example/lib/screens/widgets/permissions_block.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import 'dart:async';
22
import 'dart:io';
33

44
import 'package:firebase_messaging/firebase_messaging.dart';
5-
import 'package:flutter/foundation.dart';
65
import 'package:flutter/material.dart';
76
import 'package:twilio_voice/twilio_voice.dart';
87
import 'package:twilio_voice_example/screens/widgets/permission_tile.dart';
98
import 'package:twilio_voice_example/screens/widgets/state_toggle.dart';
109

10+
import '../../utils.dart';
11+
1112
class PermissionsBlock extends StatefulWidget {
1213
const PermissionsBlock({super.key});
1314

@@ -119,7 +120,7 @@ class _PermissionsBlockState extends State<PermissionsBlock> with WidgetsBinding
119120

120121
@override
121122
void didChangeAppLifecycleState(AppLifecycleState state) {
122-
print("AppLifecycleState: $state");
123+
printDebug("AppLifecycleState: $state");
123124
if(_lastLifecycleState != state && state == AppLifecycleState.resumed) {
124125
_updatePermissions();
125126
}
@@ -322,7 +323,7 @@ class _PermissionsBlockState extends State<PermissionsBlock> with WidgetsBinding
322323
title: "Phone Account",
323324
granted: _hasRegisteredPhoneAccount,
324325
onRequestPermission: () async {
325-
final result = await _tv.registerPhoneAccount();
326+
await _tv.registerPhoneAccount();
326327
setPhoneAccountRegistered = await _tv.hasRegisteredPhoneAccount();
327328
},
328329
),
@@ -337,7 +338,7 @@ class _PermissionsBlockState extends State<PermissionsBlock> with WidgetsBinding
337338
subtitle: Text(_hasRegisteredPhoneAccount ? (_isPhoneAccountEnabled ? "Enabled" : "Not Enabled") : "Not Registered"),
338339
trailing: ElevatedButton(
339340
onPressed: _hasRegisteredPhoneAccount && !_isPhoneAccountEnabled ? () => _tv.openPhoneAccountSettings() : null,
340-
child: Text("Open Settings"),
341+
child: const Text("Open Settings"),
341342
),
342343
),
343344
],

example/lib/utils.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'package:flutter/foundation.dart';
2+
3+
void printDebug(String message) {
4+
if (kDebugMode) {
5+
print(message);
6+
}
7+
}

lib/_internal/js/core/promise.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import 'package:js/js.dart';
44

55
@JS()
66
abstract class Promise<T> {
7-
external factory Promise(
8-
void executor(void resolve(T result), Function reject));
9-
external Promise then(void onFulfilled(T result), [Function onRejected]);
7+
external factory Promise(void Function(Function(T result) resolve, Function reject) executor);
8+
external Promise then(void Function(T result) onFulfilled, [Function onRejected]);
109
}
1110

1211
Future<Map<String, dynamic>> parsePromise(Promise<dynamic> promise) async {

lib/_internal/js/utils/js_object_utils.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import 'package:js/js.dart';
22
import 'package:js/js_util.dart';
33

4-
/// A workaround to converting an object from JS to a Dart Map.
5-
Map jsToMap(jsObject) {
6-
return new Map.fromIterable(
7-
objectKeys(jsObject),
8-
value: (key) => getProperty(jsObject, key),
9-
);
10-
}
11-
124
Map<String, String> jsToStringMap(dynamic jsonObject) {
135
final map = <String, String>{};
146
final keys = objectKeys(jsonObject);

lib/_internal/method_channel/twilio_call_method_channel.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class MethodChannelTwilioCall extends TwilioCallPlatform {
2626
Future<bool?> place({required String from, required String to, Map<String, dynamic>? extraOptions}) {
2727
_activeCall = ActiveCall(from: from, to: to, callDirection: CallDirection.outgoing);
2828

29-
var options = extraOptions ?? Map<String, dynamic>();
29+
var options = extraOptions ?? <String, dynamic>{};
3030
options['From'] = from;
3131
options['To'] = to;
3232
return _channel.invokeMethod('makeCall', options);
@@ -65,6 +65,7 @@ class MethodChannelTwilioCall extends TwilioCallPlatform {
6565
}
6666

6767
/// Query's active call holding state
68+
@override
6869
Future<bool?> isHolding() {
6970
return _channel.invokeMethod('isHolding', <String, dynamic>{});
7071
}
@@ -76,6 +77,7 @@ class MethodChannelTwilioCall extends TwilioCallPlatform {
7677
}
7778

7879
/// Query's mute status of call, true if call is muted
80+
@override
7981
Future<bool?> isMuted() {
8082
return _channel.invokeMethod('isMuted', <String, dynamic>{});
8183
}
@@ -92,6 +94,7 @@ class MethodChannelTwilioCall extends TwilioCallPlatform {
9294
}*/
9395

9496
/// Query's speaker output status, true if on loud speaker.
97+
@override
9598
Future<bool?> isOnSpeaker() {
9699
return _channel.invokeMethod('isOnSpeaker', <String, dynamic>{});
97100
}

0 commit comments

Comments
 (0)