flutter_permissions_helper 0.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 80

flutter_permissions_helper #

A Flutter package for easily requesting permissions from the mobile OS, prompting the user to grant or deny access to the specified resource.

Based on the simple_permissions package. This package refactors the code into a more extensible structure and extends support to all mobile OS versions supported by Flutter.

Requirements #

This package is compatable with all versions of Android or iOS that are compatable with Flutter. (Some specific permissions are restricted to certain versions. Details in the permissions reference table below.)

API Reference #

static Future<bool> hasPermission(Permission)

Checks to see if the app has been granted access to a particular permission.

static Future<PermissionStatus> requestPermission(Permission)

Requests a permission from the mobile platform. This usually entails a display window showing on the app, asking the user if they would like to allow the app access to that permission.

If the permission has already been granted, this function will automatically return PermissionStatus.Granted.

static Future<PermissionStatus> getPermissionStatus(Permission)

Returns the exact PermissionStatus of a given permission.

enum Permission

An enum containing all the permissions this package supports requesting from the mobile platform.

See Permissions Reference below for a list of values.

enum PermissionStatus

An enum representing the status of permissions for the app. This enum is returned by several functions illustrating the state of the permission queried.

  • Undetermined: The default value for a permission that has not yet been requested.
  • Restricted: The permission has been granted but with restrictions on its functionality.
  • Denied: The permission has been denied by the user.
  • DeniedAndDisabled: The permission has been denied by the user and any further requests are automatically blocked. (Android only)
  • Granted: The permission has been granted.

Permissions Reference #

Below is a list of permission codes supported by the plugin and their respective support on each mobile platform. Synonym means a permission is treated as though it is another permission type, usually as a means of convenience. Implicit means that it is not necessary to request the permission on that platform.

PermissioniOS SupportAndroid Support
AccessCourseLocationAny (Synonym: WHEN_IN_USE_LOCATION)Any
AccessFineLocationAny (Synonym: WHEN_IN_USE_LOCATION)Any
AlwaysLocationAnyAny (Synonym: ACCESS_FINE_LOCATION)
CallPhoneNot SupportedAny
CameraAnyAny
PhotoLibraryAnyNot Supported
ReadContacts9.0+Any
ReadExternalStorageAny (Implicit)Any
ReadPhoneStateNot SupportedAny
ReadSmsNot SupportedAny
RecordAudioAnyAny
VibrateNot ImplementedAny
WhenInUseLocationAnyAny (Synonym: ACCESS_FINE_LOCATION)
WriteContacts9.0+Any
WriteExternalStorageAny (Implicit)Any

0.0.4 #

  • Added content to CHANGELOG.md

0.0.3 #

  • Added content to README.md

0.0.2 #

  • Changed ReadExternalStorage and WriteExternalStorage on iOS to be implicitly granted.

0.0.1 #

  • Initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_permissions_helper/permissions_helper.dart';

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

class MyApp extends StatefulWidget {
    @override
    _MyAppState createState() =>  _MyAppState();
}

class _MyAppState extends State<MyApp> {
    String _platformVersion = 'Unknown';
    Permission permission;

    @override
    initState() {
        super.initState();
    }

    @override
    Widget build(BuildContext context) {
        return MaterialApp(
            home: Scaffold(
                appBar: AppBar(
                    title: Text('Permission Helper Test App'),
                ),
                body: Center(
                    child: IntrinsicWidth(
                        child: Column(
                            crossAxisAlignment: CrossAxisAlignment.stretch,
                            children: <Widget>[
                                SizedBox(height: 16.0),
                                Container(
                                    decoration: BoxDecoration(
                                        color: Color.fromARGB(255, 224, 224, 224),
                                        borderRadius: BorderRadius.all(Radius.circular(3.0)),
                                        boxShadow: [
                                            BoxShadow(
                                                color: Color.fromARGB(255, 197, 197, 197), 
                                                offset: Offset(0.0, 2.0),
                                                blurRadius: 1.0,
                                                spreadRadius: -1.0,
                                            ),
                                        ]
                                    ),
                                    child: DropdownButton(
                                        items: _getDropDownItems(), 
                                        value: permission, 
                                        onChanged: onDropDownChanged
                                    ),
                                ),
                                SizedBox(height: 8.0),
                                RaisedButton( 
                                    child: Text("Check permission"),
                                    onPressed: checkPermission,
                                ),
                                SizedBox(height: 8.0),
                                RaisedButton(
                                    child: Text("Request permission"),
                                    onPressed: requestPermission, 
                                ),
                                SizedBox(height: 8.0),
                                RaisedButton(
                                    child: Text("Get permission status"),
                                    onPressed: getPermissionStatus, 
                                ),
                                SizedBox(height: 8.0),
                                RaisedButton(
                                    child: Text("Open settings"),
                                    onPressed: PermissionsHelper.openSettings, 
                                ),
                            ]
                        ),
                    ),
                )
            ),
        );
    }

    onDropDownChanged(Permission permission) {
        setState(() => this.permission = permission);
        print(permission);
    }

    requestPermission() async {
        var res = await PermissionsHelper.requestPermission(permission);
        print("permission request result is " + res.toString());
    }

    checkPermission() async {
     bool res = await PermissionsHelper.hasPermission(permission);
     print("permission is " + res.toString());
    }

    getPermissionStatus() async {
        final res = await PermissionsHelper.getPermissionStatus(permission);
        print("permission status is " + res.toString());
    }

    List<DropdownMenuItem<Permission>>_getDropDownItems() {
        List<DropdownMenuItem<Permission>> items =  List();
        Permission.values.forEach((permission) {
            var item  =  DropdownMenuItem(child:  Text(permissionToString(permission)), value: permission);
            items.add(item);
        });
        return items;
    }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_permissions_helper: ^0.0.4

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:flutter_permissions_helper/enums.dart';
import 'package:flutter_permissions_helper/permissions_helper.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
69
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
78
Overall:
Weighted score of the above. [more]
80
Learn more about scoring.

We analyzed this package on Oct 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

57 out of 57 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/enums.dart.

Run flutter format to format lib/enums.dart.

Format lib/permissions_helper.dart.

Run flutter format to format lib/permissions_helper.dart.

Maintenance suggestions

Package is getting outdated. (-12.33 points)

The package was last published 58 weeks ago.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8