2023-11-04 22:40:11 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2023-11-02 17:19:39 +00:00
|
|
|
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 {
|
2023-11-04 22:40:11 +00:00
|
|
|
if (Platform.isIOS) {
|
|
|
|
return true;
|
|
|
|
}
|
2023-11-02 17:19:39 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|