mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
CW-315-Add-a-toast-message-to-enable-denied-permissions-in-device-settings (#1157)
* add permission handler * localization * minor fixes --------- Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/utils/show_bar.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
class PermissionHandler {
|
||||
static Future<bool> checkPermission(Permission permission, BuildContext context) async {
|
||||
final Map<Permission, String> _permissionMessages = {
|
||||
Permission.camera: S.of(context).camera_permission_is_required,
|
||||
};
|
||||
|
||||
var status = await permission.status;
|
||||
|
||||
if (status.isDenied) {
|
||||
status = await permission.request();
|
||||
}
|
||||
|
||||
if (status.isPermanentlyDenied || status.isDenied) {
|
||||
String? message = _permissionMessages[permission];
|
||||
if (message != null) {
|
||||
showBar<void>(context, message);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (status.isGranted) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user