Skip to content

Commit

Permalink
null safety.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc committed Jun 11, 2021
1 parent f3e799a commit 1052eda
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 43 deletions.
34 changes: 17 additions & 17 deletions lib/src/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ class CallKeepDidReceiveStartCallAction extends EventType {
: callUUID = arguments['callUUID'] as String,
handle = arguments['handle'] as String,
name = arguments['name'] as String;
String callUUID;
String handle;
String name;
String? callUUID;
String? handle;
String? name;
}

class CallKeepPerformAnswerCallAction extends EventType {
CallKeepPerformAnswerCallAction();
CallKeepPerformAnswerCallAction.fromMap(Map<dynamic, dynamic> arguments)
: callUUID = arguments['callUUID'] as String;
String callUUID;
String? callUUID;
}

class CallKeepPerformEndCallAction extends EventType {
CallKeepPerformEndCallAction();
CallKeepPerformEndCallAction.fromMap(Map<dynamic, dynamic> arguments)
: callUUID = arguments['callUUID'] as String;
String callUUID;
String? callUUID;
}

class CallKeepDidActivateAudioSession extends EventType {
Expand All @@ -41,38 +41,38 @@ class CallKeepDidDisplayIncomingCall extends EventType {
localizedCallerName = arguments['localizedCallerName'] as String,
hasVideo = arguments['hasVideo'] as bool,
fromPushKit = arguments['fromPushKit'] as bool;
String callUUID;
String handle;
String localizedCallerName;
bool hasVideo;
bool fromPushKit;
String? callUUID;
String? handle;
String? localizedCallerName;
bool? hasVideo;
bool? fromPushKit;
}

class CallKeepDidPerformSetMutedCallAction extends EventType {
CallKeepDidPerformSetMutedCallAction();
CallKeepDidPerformSetMutedCallAction.fromMap(Map<dynamic, dynamic> arguments)
: callUUID = arguments['callUUID'] as String,
muted = arguments['muted'] as bool;
String callUUID;
bool muted;
String? callUUID;
bool? muted;
}

class CallKeepDidToggleHoldAction extends EventType {
CallKeepDidToggleHoldAction();
CallKeepDidToggleHoldAction.fromMap(Map<dynamic, dynamic> arguments)
: callUUID = arguments['callUUID'] as String,
hold = arguments['hold'] as bool;
String callUUID;
bool hold;
String? callUUID;
bool? hold;
}

class CallKeepDidPerformDTMFAction extends EventType {
CallKeepDidPerformDTMFAction();
CallKeepDidPerformDTMFAction.fromMap(Map<dynamic, dynamic> arguments)
: callUUID = arguments['callUUID'] as String,
digits = arguments['digits'] as String;
String callUUID;
String digits;
String? callUUID;
String? digits;
}

class CallKeepProviderReset extends EventType {
Expand All @@ -91,5 +91,5 @@ class CallKeepPushKitToken extends EventType {
CallKeepPushKitToken();
CallKeepPushKitToken.fromMap(Map<dynamic, dynamic> arguments)
: token = arguments['token'] as String;
String token;
String? token;
}
74 changes: 50 additions & 24 deletions lib/src/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import 'dart:io';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart'
show
showDialog,
AlertDialog,
BuildContext,
FlatButton,
Navigator,
Text,
Widget;
TextButton,
Widget,
showDialog;
import 'package:flutter/services.dart' show MethodChannel;

import 'actions.dart';
Expand All @@ -29,7 +30,7 @@ class FlutterCallkeep extends EventManager {
static final FlutterCallkeep _instance = FlutterCallkeep._internal();
static const MethodChannel _channel = MethodChannel('FlutterCallKeep.Method');
static const MethodChannel _event = MethodChannel('FlutterCallKeep.Event');
BuildContext _context;
BuildContext? _context;

Future<void> setup(Map<String, dynamic> options) async {
if (!isIOS) {
Expand Down Expand Up @@ -64,7 +65,7 @@ class FlutterCallkeep extends EventManager {
return true;
}

Future<bool> _checkDefaultPhoneAccount() async {
Future<bool?> _checkDefaultPhoneAccount() async {
return await _channel
.invokeMethod<bool>('checkDefaultPhoneAccount', <String, dynamic>{});
}
Expand Down Expand Up @@ -161,8 +162,14 @@ class FlutterCallkeep extends EventManager {
}
}

Future<bool> isCallActive(String uuid) async => await _channel
.invokeMethod<bool>('isCallActive', <String, dynamic>{'uuid': uuid});
Future<bool> isCallActive(String uuid) async {
var resp = await _channel
.invokeMethod<bool>('isCallActive', <String, dynamic>{'uuid': uuid});
if (resp != null) {
return resp;
}
return false;
}

Future<void> endCall(String uuid) async => await _channel
.invokeMethod<void>('endCall', <String, dynamic>{'uuid': uuid});
Expand All @@ -174,16 +181,24 @@ class FlutterCallkeep extends EventManager {
if (isIOS) {
return true;
}
return await _channel
var resp = await _channel
.invokeMethod<bool>('hasPhoneAccount', <String, dynamic>{});
if (resp != null) {
return resp;
}
return false;
}

Future<bool> hasOutgoingCall() async {
if (isIOS) {
return true;
}
return await _channel
var resp = await _channel
.invokeMethod<bool>('hasOutgoingCall', <String, dynamic>{});
if (resp != null) {
return resp;
}
return false;
}

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

Future<void> updateDisplay(String uuid,
{String displayName, String handle}) async =>
{required String displayName, required String handle}) async =>
await _channel.invokeMethod<void>('updateDisplay', <String, dynamic>{
'uuid': uuid,
'displayName': displayName,
Expand Down Expand Up @@ -259,9 +274,12 @@ class FlutterCallkeep extends EventManager {
if (isIOS) {
return false;
}

return await _channel
var resp = await _channel
.invokeMethod<bool>('backToForeground', <String, dynamic>{});
if (resp != null) {
return resp;
}
return false;
}

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

if (shouldOpenAccounts) {
Expand All @@ -297,46 +315,54 @@ class FlutterCallkeep extends EventManager {
}

Future<bool> _checkPhoneAccountPermission(
[List<String> optionalPermissions]) async {
List<String>? optionalPermissions) async {
if (!Platform.isAndroid) {
return true;
}
return await _channel
var resp = await _channel
.invokeMethod<bool>('checkPhoneAccountPermission', <String, dynamic>{
'optionalPermissions': optionalPermissions ?? <String>[],
'optionalPermissions': optionalPermissions ?? [],
});
if (resp != null) {
return resp;
}
return false;
}

Future<bool> _alert(Map<String, dynamic> options, bool condition) async {
Future<bool> _alert(Map<String, dynamic> options, bool? condition) async {
if (_context == null) {
return false;
}
return await _showAlertDialog(
_context,
var resp = await _showAlertDialog(
_context!,
options['alertTitle'] as String,
options['alertDescription'] as String,
options['cancelButton'] as String,
options['okButton'] as String);
if (resp != null) {
return resp;
}
return false;
}

Future<bool> _showAlertDialog(BuildContext context, String alertTitle,
String alertDescription, String cancelButton, String okButton) {
Future<bool?> _showAlertDialog(BuildContext context, String? alertTitle,
String? alertDescription, String? cancelButton, String? okButton) {
return showDialog<bool>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: Text(alertTitle ?? 'Permissions required'),
content: Text(alertDescription ??
'This application needs to access your phone accounts'),
actions: <Widget>[
FlatButton(
child: Text(cancelButton ?? 'Cancel'),
TextButton(
onPressed: () =>
Navigator.of(context, rootNavigator: true).pop(false),
child: Text(cancelButton ?? 'Cancel'),
),
FlatButton(
child: Text(okButton ?? 'ok'),
TextButton(
onPressed: () =>
Navigator.of(context, rootNavigator: true).pop(true),
child: Text(okButton ?? 'ok'),
),
],
),
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version: 0.2.4
homepage: https://github.com/flutter-webrtc/callkeep

environment:
sdk: ">=2.2.2 <3.0.0"
flutter: ^1.10.0
sdk: '>=2.12.0 <3.0.0'
flutter: '>=1.22.0'

dependencies:
flutter:
Expand Down

0 comments on commit 1052eda

Please sign in to comment.