Skip to content

Commit 1052eda

Browse files
committed
null safety.
1 parent f3e799a commit 1052eda

File tree

3 files changed

+69
-43
lines changed

3 files changed

+69
-43
lines changed

lib/src/actions.dart

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ class CallKeepDidReceiveStartCallAction extends EventType {
66
: callUUID = arguments['callUUID'] as String,
77
handle = arguments['handle'] as String,
88
name = arguments['name'] as String;
9-
String callUUID;
10-
String handle;
11-
String name;
9+
String? callUUID;
10+
String? handle;
11+
String? name;
1212
}
1313

1414
class CallKeepPerformAnswerCallAction extends EventType {
1515
CallKeepPerformAnswerCallAction();
1616
CallKeepPerformAnswerCallAction.fromMap(Map<dynamic, dynamic> arguments)
1717
: callUUID = arguments['callUUID'] as String;
18-
String callUUID;
18+
String? callUUID;
1919
}
2020

2121
class CallKeepPerformEndCallAction extends EventType {
2222
CallKeepPerformEndCallAction();
2323
CallKeepPerformEndCallAction.fromMap(Map<dynamic, dynamic> arguments)
2424
: callUUID = arguments['callUUID'] as String;
25-
String callUUID;
25+
String? callUUID;
2626
}
2727

2828
class CallKeepDidActivateAudioSession extends EventType {
@@ -41,38 +41,38 @@ class CallKeepDidDisplayIncomingCall extends EventType {
4141
localizedCallerName = arguments['localizedCallerName'] as String,
4242
hasVideo = arguments['hasVideo'] as bool,
4343
fromPushKit = arguments['fromPushKit'] as bool;
44-
String callUUID;
45-
String handle;
46-
String localizedCallerName;
47-
bool hasVideo;
48-
bool fromPushKit;
44+
String? callUUID;
45+
String? handle;
46+
String? localizedCallerName;
47+
bool? hasVideo;
48+
bool? fromPushKit;
4949
}
5050

5151
class CallKeepDidPerformSetMutedCallAction extends EventType {
5252
CallKeepDidPerformSetMutedCallAction();
5353
CallKeepDidPerformSetMutedCallAction.fromMap(Map<dynamic, dynamic> arguments)
5454
: callUUID = arguments['callUUID'] as String,
5555
muted = arguments['muted'] as bool;
56-
String callUUID;
57-
bool muted;
56+
String? callUUID;
57+
bool? muted;
5858
}
5959

6060
class CallKeepDidToggleHoldAction extends EventType {
6161
CallKeepDidToggleHoldAction();
6262
CallKeepDidToggleHoldAction.fromMap(Map<dynamic, dynamic> arguments)
6363
: callUUID = arguments['callUUID'] as String,
6464
hold = arguments['hold'] as bool;
65-
String callUUID;
66-
bool hold;
65+
String? callUUID;
66+
bool? hold;
6767
}
6868

6969
class CallKeepDidPerformDTMFAction extends EventType {
7070
CallKeepDidPerformDTMFAction();
7171
CallKeepDidPerformDTMFAction.fromMap(Map<dynamic, dynamic> arguments)
7272
: callUUID = arguments['callUUID'] as String,
7373
digits = arguments['digits'] as String;
74-
String callUUID;
75-
String digits;
74+
String? callUUID;
75+
String? digits;
7676
}
7777

7878
class CallKeepProviderReset extends EventType {
@@ -91,5 +91,5 @@ class CallKeepPushKitToken extends EventType {
9191
CallKeepPushKitToken();
9292
CallKeepPushKitToken.fromMap(Map<dynamic, dynamic> arguments)
9393
: token = arguments['token'] as String;
94-
String token;
94+
String? token;
9595
}

lib/src/api.dart

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import 'dart:io';
33
import 'package:flutter/services.dart';
44
import 'package:flutter/material.dart'
55
show
6-
showDialog,
76
AlertDialog,
87
BuildContext,
98
FlatButton,
109
Navigator,
1110
Text,
12-
Widget;
11+
TextButton,
12+
Widget,
13+
showDialog;
1314
import 'package:flutter/services.dart' show MethodChannel;
1415

1516
import 'actions.dart';
@@ -29,7 +30,7 @@ class FlutterCallkeep extends EventManager {
2930
static final FlutterCallkeep _instance = FlutterCallkeep._internal();
3031
static const MethodChannel _channel = MethodChannel('FlutterCallKeep.Method');
3132
static const MethodChannel _event = MethodChannel('FlutterCallKeep.Event');
32-
BuildContext _context;
33+
BuildContext? _context;
3334

3435
Future<void> setup(Map<String, dynamic> options) async {
3536
if (!isIOS) {
@@ -64,7 +65,7 @@ class FlutterCallkeep extends EventManager {
6465
return true;
6566
}
6667

67-
Future<bool> _checkDefaultPhoneAccount() async {
68+
Future<bool?> _checkDefaultPhoneAccount() async {
6869
return await _channel
6970
.invokeMethod<bool>('checkDefaultPhoneAccount', <String, dynamic>{});
7071
}
@@ -161,8 +162,14 @@ class FlutterCallkeep extends EventManager {
161162
}
162163
}
163164

164-
Future<bool> isCallActive(String uuid) async => await _channel
165-
.invokeMethod<bool>('isCallActive', <String, dynamic>{'uuid': uuid});
165+
Future<bool> isCallActive(String uuid) async {
166+
var resp = await _channel
167+
.invokeMethod<bool>('isCallActive', <String, dynamic>{'uuid': uuid});
168+
if (resp != null) {
169+
return resp;
170+
}
171+
return false;
172+
}
166173

167174
Future<void> endCall(String uuid) async => await _channel
168175
.invokeMethod<void>('endCall', <String, dynamic>{'uuid': uuid});
@@ -174,16 +181,24 @@ class FlutterCallkeep extends EventManager {
174181
if (isIOS) {
175182
return true;
176183
}
177-
return await _channel
184+
var resp = await _channel
178185
.invokeMethod<bool>('hasPhoneAccount', <String, dynamic>{});
186+
if (resp != null) {
187+
return resp;
188+
}
189+
return false;
179190
}
180191

181192
Future<bool> hasOutgoingCall() async {
182193
if (isIOS) {
183194
return true;
184195
}
185-
return await _channel
196+
var resp = await _channel
186197
.invokeMethod<bool>('hasOutgoingCall', <String, dynamic>{});
198+
if (resp != null) {
199+
return resp;
200+
}
201+
return false;
187202
}
188203

189204
Future<void> setMutedCall(String uuid, bool shouldMute) async =>
@@ -221,7 +236,7 @@ class FlutterCallkeep extends EventManager {
221236
}
222237

223238
Future<void> updateDisplay(String uuid,
224-
{String displayName, String handle}) async =>
239+
{required String displayName, required String handle}) async =>
225240
await _channel.invokeMethod<void>('updateDisplay', <String, dynamic>{
226241
'uuid': uuid,
227242
'displayName': displayName,
@@ -259,9 +274,12 @@ class FlutterCallkeep extends EventManager {
259274
if (isIOS) {
260275
return false;
261276
}
262-
263-
return await _channel
277+
var resp = await _channel
264278
.invokeMethod<bool>('backToForeground', <String, dynamic>{});
279+
if (resp != null) {
280+
return resp;
281+
}
282+
return false;
265283
}
266284

267285
Future<void> _setupIOS(Map<String, dynamic> options) async {
@@ -279,7 +297,7 @@ class FlutterCallkeep extends EventManager {
279297
Future<bool> _setupAndroid(Map<String, dynamic> options) async {
280298
await _channel.invokeMethod<void>('setup', {'options': options});
281299
final showAccountAlert = await _checkPhoneAccountPermission(
282-
options['additionalPermissions'] as List<String> ?? <String>[]);
300+
options['additionalPermissions'] as List<String>);
283301
final shouldOpenAccounts = await _alert(options, showAccountAlert);
284302

285303
if (shouldOpenAccounts) {
@@ -297,46 +315,54 @@ class FlutterCallkeep extends EventManager {
297315
}
298316

299317
Future<bool> _checkPhoneAccountPermission(
300-
[List<String> optionalPermissions]) async {
318+
List<String>? optionalPermissions) async {
301319
if (!Platform.isAndroid) {
302320
return true;
303321
}
304-
return await _channel
322+
var resp = await _channel
305323
.invokeMethod<bool>('checkPhoneAccountPermission', <String, dynamic>{
306-
'optionalPermissions': optionalPermissions ?? <String>[],
324+
'optionalPermissions': optionalPermissions ?? [],
307325
});
326+
if (resp != null) {
327+
return resp;
328+
}
329+
return false;
308330
}
309331

310-
Future<bool> _alert(Map<String, dynamic> options, bool condition) async {
332+
Future<bool> _alert(Map<String, dynamic> options, bool? condition) async {
311333
if (_context == null) {
312334
return false;
313335
}
314-
return await _showAlertDialog(
315-
_context,
336+
var resp = await _showAlertDialog(
337+
_context!,
316338
options['alertTitle'] as String,
317339
options['alertDescription'] as String,
318340
options['cancelButton'] as String,
319341
options['okButton'] as String);
342+
if (resp != null) {
343+
return resp;
344+
}
345+
return false;
320346
}
321347

322-
Future<bool> _showAlertDialog(BuildContext context, String alertTitle,
323-
String alertDescription, String cancelButton, String okButton) {
348+
Future<bool?> _showAlertDialog(BuildContext context, String? alertTitle,
349+
String? alertDescription, String? cancelButton, String? okButton) {
324350
return showDialog<bool>(
325351
context: context,
326352
builder: (BuildContext context) => AlertDialog(
327353
title: Text(alertTitle ?? 'Permissions required'),
328354
content: Text(alertDescription ??
329355
'This application needs to access your phone accounts'),
330356
actions: <Widget>[
331-
FlatButton(
332-
child: Text(cancelButton ?? 'Cancel'),
357+
TextButton(
333358
onPressed: () =>
334359
Navigator.of(context, rootNavigator: true).pop(false),
360+
child: Text(cancelButton ?? 'Cancel'),
335361
),
336-
FlatButton(
337-
child: Text(okButton ?? 'ok'),
362+
TextButton(
338363
onPressed: () =>
339364
Navigator.of(context, rootNavigator: true).pop(true),
365+
child: Text(okButton ?? 'ok'),
340366
),
341367
],
342368
),

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ version: 0.2.4
44
homepage: https://github.com/flutter-webrtc/callkeep
55

66
environment:
7-
sdk: ">=2.2.2 <3.0.0"
8-
flutter: ^1.10.0
7+
sdk: '>=2.12.0 <3.0.0'
8+
flutter: '>=1.22.0'
99

1010
dependencies:
1111
flutter:

0 commit comments

Comments
 (0)