diff --git a/lib/src/actions.dart b/lib/src/actions.dart index fef42eb..f87669e 100644 --- a/lib/src/actions.dart +++ b/lib/src/actions.dart @@ -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 arguments) : callUUID = arguments['callUUID'] as String; - String callUUID; + String? callUUID; } class CallKeepPerformEndCallAction extends EventType { CallKeepPerformEndCallAction(); CallKeepPerformEndCallAction.fromMap(Map arguments) : callUUID = arguments['callUUID'] as String; - String callUUID; + String? callUUID; } class CallKeepDidActivateAudioSession extends EventType { @@ -41,11 +41,11 @@ 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 { @@ -53,8 +53,8 @@ class CallKeepDidPerformSetMutedCallAction extends EventType { CallKeepDidPerformSetMutedCallAction.fromMap(Map arguments) : callUUID = arguments['callUUID'] as String, muted = arguments['muted'] as bool; - String callUUID; - bool muted; + String? callUUID; + bool? muted; } class CallKeepDidToggleHoldAction extends EventType { @@ -62,8 +62,8 @@ class CallKeepDidToggleHoldAction extends EventType { CallKeepDidToggleHoldAction.fromMap(Map arguments) : callUUID = arguments['callUUID'] as String, hold = arguments['hold'] as bool; - String callUUID; - bool hold; + String? callUUID; + bool? hold; } class CallKeepDidPerformDTMFAction extends EventType { @@ -71,8 +71,8 @@ class CallKeepDidPerformDTMFAction extends EventType { CallKeepDidPerformDTMFAction.fromMap(Map arguments) : callUUID = arguments['callUUID'] as String, digits = arguments['digits'] as String; - String callUUID; - String digits; + String? callUUID; + String? digits; } class CallKeepProviderReset extends EventType { @@ -91,5 +91,5 @@ class CallKeepPushKitToken extends EventType { CallKeepPushKitToken(); CallKeepPushKitToken.fromMap(Map arguments) : token = arguments['token'] as String; - String token; + String? token; } diff --git a/lib/src/api.dart b/lib/src/api.dart index 51b2222..6d435b3 100644 --- a/lib/src/api.dart +++ b/lib/src/api.dart @@ -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'; @@ -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 setup(Map options) async { if (!isIOS) { @@ -64,7 +65,7 @@ class FlutterCallkeep extends EventManager { return true; } - Future _checkDefaultPhoneAccount() async { + Future _checkDefaultPhoneAccount() async { return await _channel .invokeMethod('checkDefaultPhoneAccount', {}); } @@ -161,8 +162,14 @@ class FlutterCallkeep extends EventManager { } } - Future isCallActive(String uuid) async => await _channel - .invokeMethod('isCallActive', {'uuid': uuid}); + Future isCallActive(String uuid) async { + var resp = await _channel + .invokeMethod('isCallActive', {'uuid': uuid}); + if (resp != null) { + return resp; + } + return false; + } Future endCall(String uuid) async => await _channel .invokeMethod('endCall', {'uuid': uuid}); @@ -174,16 +181,24 @@ class FlutterCallkeep extends EventManager { if (isIOS) { return true; } - return await _channel + var resp = await _channel .invokeMethod('hasPhoneAccount', {}); + if (resp != null) { + return resp; + } + return false; } Future hasOutgoingCall() async { if (isIOS) { return true; } - return await _channel + var resp = await _channel .invokeMethod('hasOutgoingCall', {}); + if (resp != null) { + return resp; + } + return false; } Future setMutedCall(String uuid, bool shouldMute) async => @@ -221,7 +236,7 @@ class FlutterCallkeep extends EventManager { } Future updateDisplay(String uuid, - {String displayName, String handle}) async => + {required String displayName, required String handle}) async => await _channel.invokeMethod('updateDisplay', { 'uuid': uuid, 'displayName': displayName, @@ -259,9 +274,12 @@ class FlutterCallkeep extends EventManager { if (isIOS) { return false; } - - return await _channel + var resp = await _channel .invokeMethod('backToForeground', {}); + if (resp != null) { + return resp; + } + return false; } Future _setupIOS(Map options) async { @@ -279,7 +297,7 @@ class FlutterCallkeep extends EventManager { Future _setupAndroid(Map options) async { await _channel.invokeMethod('setup', {'options': options}); final showAccountAlert = await _checkPhoneAccountPermission( - options['additionalPermissions'] as List ?? []); + options['additionalPermissions'] as List); final shouldOpenAccounts = await _alert(options, showAccountAlert); if (shouldOpenAccounts) { @@ -297,30 +315,38 @@ class FlutterCallkeep extends EventManager { } Future _checkPhoneAccountPermission( - [List optionalPermissions]) async { + List? optionalPermissions) async { if (!Platform.isAndroid) { return true; } - return await _channel + var resp = await _channel .invokeMethod('checkPhoneAccountPermission', { - 'optionalPermissions': optionalPermissions ?? [], + 'optionalPermissions': optionalPermissions ?? [], }); + if (resp != null) { + return resp; + } + return false; } - Future _alert(Map options, bool condition) async { + Future _alert(Map 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 _showAlertDialog(BuildContext context, String alertTitle, - String alertDescription, String cancelButton, String okButton) { + Future _showAlertDialog(BuildContext context, String? alertTitle, + String? alertDescription, String? cancelButton, String? okButton) { return showDialog( context: context, builder: (BuildContext context) => AlertDialog( @@ -328,15 +354,15 @@ class FlutterCallkeep extends EventManager { content: Text(alertDescription ?? 'This application needs to access your phone accounts'), actions: [ - 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'), ), ], ), diff --git a/pubspec.yaml b/pubspec.yaml index 4de89af..97e2c5c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: