Skip to content
This repository was archived by the owner on Jan 5, 2021. It is now read-only.

Commit d9f539e

Browse files
committed
Merge branch 'master' of https://github.com/todo-devs/todo
2 parents 6d0a5c4 + 721fee8 commit d9f539e

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

lib/services/permissions.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+

lib/services/phone.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import 'package:intent/intent.dart' as android_intent;
22
import 'package:intent/action.dart' as android_action;
33

4+
import 'package:todo/services/permissions.dart';
5+
46
void 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))

pubspec.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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:

pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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.

0 commit comments

Comments
 (0)