permission 0.1.0

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

permission

A new flutter plugin for getting and requesting permission on Android.

Getting Started

####Android:

Only dangerous permissions require user agreement.

Permissions are organized into groups related to a device's capabilities or features. Under this system, permission requests are handled at the group level and a single permission group corresponds to several permission declarations in the app manifest.

Dangerous permissions and permission groups.

Permission Group Permissions
CALENDAR READ_CALENDAR
WRITE_CALENDAR
CAMERA CAMERA
CONTACTS READ_CONTACTS
WRITE_CONTACTS
GET_ACCOUNTS
LOCATION ACCESS_FINE_LOCATION
ACCESS_COARSE_LOCATION
MICROPHONE RECORD_AUDIO
PHONE READ_PHONE_STATE
CALL_PHONE
READ_CALL_LOG
WRITE_CALL_LOG
ADD_VOICEMAIL
USE_SIP
PROCESS_OUTGOING_CALLS
SENSORS BODY_SENSORS
SMS SEND_SMS
RECEIVE_SMS
READ_SMS
RECEIVE_WAP_PUSH
RECEIVE_MMS
STORAGE READ_EXTERNAL_STORAGE
WRITE_EXTERNAL_STORAGE

Make sure you add the needed permissions to your Android Manifest Permission.

<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.ADD_VOICEMAIL" />
<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.BODY_SENSORS" />
<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" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Methods

import 'package:permission/permission.dart';

List<Permissions> permissions = await Permission.getPermissionStatus([PermissionName.Calendar, PermissionName.Camera]);

final result = await Permission.requestPermissions([PermissionName.Calendar, PermissionName.Camera]);

final result = await Permission.requestSinglePermission(PermissionName.Calendar);

Permission.openSettings;

iOS

Add the needed permissions to your info.plist

 <key>NSCalendarsUsageDescription</key>
 <string>Your prompt</string>
 <key>NSCameraUsageDescription</key>
 <string>Your prompt</string>
 <key>NSContactsUsageDescription</key>
 <string>Your prompt</string>
 <key>NSLocationAlwaysUsageDescription</key>
 <string>Your prompt</string>
 <key>NSLocationWhenInUseUsageDescription</key>
 <string>Your prompt</string>
 <key>NSMicrophoneUsageDescription</key>
 <string>Your prompt</string>
 <key>NSPhotoLibraryUsageDescription</key>
 <string>Your prompt</string>
 <key>NSRemindersUsageDescription</key>
 <string>Your prompt</string>

0.0.1

  • TODO: Describe initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:permission/permission.dart';

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

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

class _MyAppState extends State<MyApp> {
  String get = '';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Plugin example app'),
        ),
        body: Center(
          child: new Column(
            children: <Widget>[
              RaisedButton(onPressed: getPermissionStatus, child: new Text("Get permission status")),
              RaisedButton(onPressed: requestPermissions, child: new Text("Request permissions")),
              RaisedButton(onPressed: requestPermission, child: new Text("Request single permission")),
              RaisedButton(onPressed: Permission.openSettings, child: new Text("Open settings")),
              Text(get),
            ],
          ),
        ),
      ),
    );
  }

  getPermissionStatus() async {
    get = '';
    List<Permissions> permissions = await Permission.getPermissionStatus([PermissionName.Calendar, PermissionName.Camera, PermissionName.Contacts, PermissionName.Location, PermissionName.Microphone, PermissionName.Phone, PermissionName.Sensors, PermissionName.SMS, PermissionName.Storage]);
    permissions.forEach((permission) {
      get += '${permission.permissionName}: ${permission.permissionStatus}\n';
    });
    setState(() {
      get;
    });
  }

  requestPermissions() async {
    final res = await Permission.requestPermissions([PermissionName.Calendar, PermissionName.Camera, PermissionName.Contacts, PermissionName.Location, PermissionName.Microphone, PermissionName.Phone, PermissionName.Sensors, PermissionName.SMS, PermissionName.Storage]);
    res.forEach((permission) {});
  }

  requestPermission() async {
    final res = await Permission.requestSinglePermission(PermissionName.Calendar);
    print(res);
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  permission: ^0.1.0

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:permission/permission.dart';
  
Version Uploaded Documentation Archive
0.1.0 Sep 13, 2018 Go to the documentation of permission 0.1.0 Download permission 0.1.0 archive
0.0.9 Aug 15, 2018 Go to the documentation of permission 0.0.9 Download permission 0.0.9 archive
0.0.8 Aug 2, 2018 Go to the documentation of permission 0.0.8 Download permission 0.0.8 archive
0.0.7 Aug 1, 2018 Go to the documentation of permission 0.0.7 Download permission 0.0.7 archive
0.0.6 Aug 1, 2018 Go to the documentation of permission 0.0.6 Download permission 0.0.6 archive
0.0.5 Aug 1, 2018 Go to the documentation of permission 0.0.5 Download permission 0.0.5 archive
0.0.4 Aug 1, 2018 Go to the documentation of permission 0.0.4 Download permission 0.0.4 archive
0.0.3 Aug 1, 2018 Go to the documentation of permission 0.0.3 Download permission 0.0.3 archive
0.0.2 Aug 1, 2018 Go to the documentation of permission 0.0.2 Download permission 0.0.2 archive
0.0.1 Aug 1, 2018 Go to the documentation of permission 0.0.1 Download permission 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
89
Health:
Code health derived from static analysis. [more]
91
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
88
Learn more about scoring.

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

  • Dart: 2.1.0
  • pana: 0.12.7
  • Flutter: 1.0.0

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs (-9.29 points)

26 out of 28 API elements (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

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