easy_permission_validator 1.0.8

  • Readme
  • Changelog
  • Example
  • Installing
  • 90

Easy Permission Validator #

This package is useful when you need to manage on-demand permissions for both Android and iOS.

pub package

Usage #

To use this plugin, add easy_permission_validator as a dependency in your pubspec.yaml file.

Base use:

_permissionRequest() async {
  final permissionValidator = EasyPermissionValidator(
    context: context,
    appName: 'Easy Permission Validator',
  );
  var result = await permissionValidator.camera();
  if (result) {
    // Do something;
  }
}

You can add custom messages for other languages:

_permissionRequest() async {
  final permissionValidator = EasyPermissionValidator(
    context: context,
    appName: 'Easy Permission Validator',
    appNameColor: Colors.red,
    cancelText: 'Cancelar',
    enableLocationMessage:
        'Debe habilitar los permisos necesarios para utilizar la acción.',
    goToSettingsText: 'Ir a Configuraciones',
    permissionSettingsMessage:
        'Necesita habilitar los permisos necesarios para que la aplicación funcione correctamente',
  );
  var result = await permissionValidator.camera();
  if (result) {
    // Do something;
  }
}

In addition, you can add a custom Dialog:

_permissionWithCustomPopup() async {
  final permissionValidator = EasyPermissionValidator(
    context: context,
    appName: 'Easy Permission Validator',
    customDialog: MyAmazingCustomPopup(),
  );
  var result = await permissionValidator.camera();
  if (result) {
    // Do something;
  }
}

Caution #

Some permissions must be in the privacy policy

Permissions #

If you use any permissions from this package, you must add:

For iOS (add in ios/Runner/Info.plist):

CALENDAR:
<key>NSCalendarsUsageDescription</key>
<string>This app requires calendars access to function properly.</string>

CAMERA:
<key>NSCameraUsageDescription</key>
<string>App requires access to the camera.</string>

CONTACTS:
<key>NSContactsUsageDescription</key>
<string>This app requires contacts access to function properly.</string>

LOCATION:
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app requires location access to function properly.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app requires location access to function properly.</string>
<key>NSLocationUsageDescription</key>
<string>This app requires location access to function properly.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app requires location access to function properly.</string>

MICROPHONE:
<key>NSMicrophoneUsageDescription</key>
<string>This app requires mic access to record video.</string>

PHOTOS:
<key>NSPhotoLibraryUsageDescription</key>
<string>This app requires photo library access to function properly.</string>

SENSORS:
<key>NSMotionUsageDescription</key>
<string>This app requires motion access</string>

REMINDER:
<key>NSRemindersUsageDescription</key>
<string>This app requires reminders access to function properly.</string>

MICROPHONE:
<key>NSSpeechRecognitionUsageDescription</key>
<string>This app requires mic access to record video.</string>

For ANDROID (add in android/app/src/main/AndroidManifest.xml):

Permissions on Android

LOCATION:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

CALENDAR:
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />

STORAGE:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

CAMERA:
<uses-permission android:name="android.permission.CAMERA" />

MICROPHONE:
<uses-permission android:name="android.permission.MICROPHONE" />

SENSORS:
<uses-permission android:name="android.permission.SENSORS" />

CONTACTS:
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

PHONE:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.ADD_VOICEMAIL" />
<uses-permission android:name="android.permission.USE_SIP" />

SMS:
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_WAP_PUSH" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />

Issues #

Please file any issues, bugs or feature request as an issue on our GitHub page.

Contributions #

You can contribute by making a pull request, this package was made for the community and you have complete power to add whatever they find useful.

1.0.8 #

  • Fix lib/permission_popup.dart
  • The dependencies were updated.

1.0.7 #

  • Update last version of PermissionHandler package.
  • Library refactor

1.0.6 #

  • Update last version of PermissionHandler package.
  • Fixed storage permission with iOS devices.

1.0.5 #

  • Fix the customDialog and the messages fields.
  • Add an extra example.

1.0.4 #

  • Add LICENSE.

1.0.3 #

  • Add more detail to the description field of pubspec.yaml.

1.0.2 #

  • Add Example.

1.0.1 #

  • Add README description.

1.0.0 #

  • Initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:easy_permission_validator/easy_permission_validator.dart';
import 'package:permission_handler/permission_handler.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Easy Permission Validator Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: MyHomePage(title: 'Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String _result = '';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: MainAxisSize.max,
          children: <Widget>[
            IconButton(
              icon: Icon(Icons.camera),
              iconSize: 90.0,
              onPressed: () => _permissionWithCustomPopup(),
            ),
            Padding(
              padding: const EdgeInsets.only(top: 50.0),
              child: Text(
                _result,
                style: TextStyle(fontSize: 22.0),
              ),
            ),
          ],
        ),
      ),
    );
  }

  _permissionRequest() async {
    final permissionValidator = EasyPermissionValidator(
      context: context,
      appName: 'Easy Permission Validator',
    );
    var result = await permissionValidator.camera();
    if (result) {
      setState(() => _result = 'Permission accepted');
    }
  }

  _permissionWithCustomPopup() async {
    EasyPermissionValidator permissionValidator = EasyPermissionValidator(
      context: context,
      appName: 'Easy Permission Validator',
      customDialog: MyAmazingCustomPopup(),
    );
    var result = await permissionValidator.camera();
    if (result) {
      setState(() => _result = 'Permission accepted');
    }
  }
}

class MyAmazingCustomPopup extends StatefulWidget {
  @override
  _MyAmazingCustomPopupState createState() => _MyAmazingCustomPopupState();
}

class _MyAmazingCustomPopupState extends State<MyAmazingCustomPopup> {
  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async => false,
      child: Center(
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 13.0),
          child: SizedBox(
            height: 300.0,
            width: MediaQuery.of(context).size.width,
            child: Card(
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(10.0)),
              ),
              color: Colors.white,
              child: Padding(
                padding: const EdgeInsets.symmetric(vertical: 20.0),
                child: Column(
                  mainAxisSize: MainAxisSize.max,
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    Text(
                      'Easy Permission Validator Demo',
                      style: TextStyle(
                        color: Colors.green,
                        fontSize: 23.0,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    Icon(
                      Icons.perm_camera_mic,
                      size: 60.0,
                      color: Colors.red,
                    ),
                    Row(
                      mainAxisSize: MainAxisSize.max,
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: <Widget>[
                        FlatButton.icon(
                          icon: Icon(Icons.cancel),
                          onPressed: () => _closePopup(),
                          label: Text('Cancel'),
                        ),
                        FlatButton.icon(
                          icon: Icon(Icons.arrow_forward_ios),
                          onPressed: () => _openPermissionSettings(),
                          label: Text('Go To Settings'),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }

  _openPermissionSettings() async {
    await PermissionHandler().openAppSettings();
    _closePopup();
  }

  _closePopup() {
    Navigator.of(context).pop();
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  easy_permission_validator: ^1.0.8

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:easy_permission_validator/easy_permission_validator.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
83
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
90
Learn more about scoring.

We analyzed this package on Apr 1, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (permission_handler).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.5.0 <3.0.0
flutter 0.0.0
permission_handler ^4.4.0 4.4.0+hotfix.4 5.0.0+hotfix.3
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
permission_handler_platform_interface 1.0.0 2.0.0
plugin_platform_interface 1.0.2
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test