/*
 * @Descripttion: 获取本地权限
 * @version: UpgradePermission
 * @Author: wy
 * @Date: 2020-07-30 15:41:39
 * @LastEditors: wangyang 1147192855@qq.com
 * @LastEditTime: 2022-08-01 14:08:57
 */
import 'package:marking_app/utils/index.dart';
import 'package:permission_handler/permission_handler.dart';

class UpgradePermission {
  final String _flatform;
  const UpgradePermission(this._flatform);

  /// 检查是否有权限，用于安卓
  Future<bool> checkPermission() async {
    // if (_flatform == 'android') {

    //   return await Permission.storage.request().isGranted;
    // } else {
    //   return true;
    // }

    if (_flatform == 'android') {
      final status = await Permission.storage.status;
      if (status != PermissionStatus.granted) {
        final result = await Permission.storage.request();
        if (result == PermissionStatus.granted) {
          return true;
        }
        if (status == PermissionStatus.denied) {
          ToastUtils.showError('拒绝了保存安装权限');
        }

        if (status == PermissionStatus.permanentlyDenied) {
          ToastUtils.showError('用户永久拒绝保存安装权限，请前往设置权限');
        }
      } else {
        return true;
      }
    } else {
      return true;
    }
    return false;
  }
}
