This repository was archived by the owner on Jan 5, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +44
-0
lines changed
Expand file tree Collapse file tree 4 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ import 'package:permission_handler/permission_handler.dart' ;
2+
3+ class PermissionsService {
4+ final PermissionHandler _permissionHandler = PermissionHandler ();
5+
6+ Future <bool > requestPermission (PermissionGroup permission) async {
7+ var result = await _permissionHandler.requestPermissions ([permission]);
8+ if (result[permission] == PermissionStatus .granted) {
9+ return true ;
10+ }
11+
12+ return false ;
13+ }
14+
15+ Future <bool > hasPermission (PermissionGroup permission) async {
16+ var permissionStatus =
17+ await _permissionHandler.checkPermissionStatus (permission);
18+ return permissionStatus == PermissionStatus .granted;
19+ }
20+
21+ Future <bool > requestPhonePermission () async {
22+ return requestPermission (PermissionGroup .phone);
23+ }
24+
25+ Future <bool > hasPhonePermission () async {
26+ return hasPermission (PermissionGroup .phone);
27+ }
28+ }
29+
Original file line number Diff line number Diff line change 11import 'package:intent/intent.dart' as android_intent;
22import 'package:intent/action.dart' as android_action;
33
4+ import 'package:todo/services/permissions.dart' ;
5+
46void callTo (String number) async {
7+ if (! await PermissionsService ().hasPhonePermission ())
8+ if (! await PermissionsService ().requestPhonePermission ())
9+ return ;
10+
511 android_intent.Intent ()
612 ..setAction (android_action.Action .ACTION_CALL )
713 ..setData (Uri (scheme: "tel" , path: number))
Original file line number Diff line number Diff line change @@ -116,6 +116,13 @@ packages:
116116 url: "https://pub.dartlang.org"
117117 source: hosted
118118 version: "1.6.4"
119+ permission_handler:
120+ dependency: "direct main"
121+ description:
122+ name: permission_handler
123+ url: "https://pub.dartlang.org"
124+ source: hosted
125+ version: "3.3.0"
119126 petitparser:
120127 dependency: transitive
121128 description:
Original file line number Diff line number Diff line change @@ -27,7 +27,9 @@ dependencies:
2727 # External depencies
2828 contact_picker :
2929 path : ./contact_picker
30+
3031 intent : ^1.3.4
32+ permission_handler : ^3.1.0
3133
3234 # The following adds the Cupertino Icons font to your application.
3335 # Use with the CupertinoIcons class for iOS style icons.
You can’t perform that action at this time.
0 commit comments