@@ -3,13 +3,14 @@ import 'dart:io';
33import 'package:flutter/services.dart' ;
44import '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;
1314import 'package:flutter/services.dart' show MethodChannel;
1415
1516import '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 ),
0 commit comments