flutter_permissions_helper 0.0.4

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 71

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 packages get

Alternatively, your editor might support flutter packages 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';
  
Version Uploaded Documentation Archive
0.0.4 Aug 27, 2018 Go to the documentation of flutter_permissions_helper 0.0.4 Download flutter_permissions_helper 0.0.4 archive
0.0.3 Aug 27, 2018 Go to the documentation of flutter_permissions_helper 0.0.3 Download flutter_permissions_helper 0.0.3 archive
0.0.2 Aug 27, 2018 Go to the documentation of flutter_permissions_helper 0.0.2 Download flutter_permissions_helper 0.0.2 archive
0.0.1 Aug 24, 2018 Go to the documentation of flutter_permissions_helper 0.0.1 Download flutter_permissions_helper 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
46
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]
71
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

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

While there is nothing inherently wrong with versions of 0.0.*, it usually means 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
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8