permissions 0.1.2

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

Permissions (Don't use this plugin, it doesn't work on iOS)

A flutter plugin for checking and requesting permissions on iOS and Android. This plugin is basically the same plugin as Vladimir Mbassi's Simple Permissions Plugin. The only difference between his plugin and mine is that mine will run on iOS 8 and above. The contacts permission only works on iOS 9 and above.

Getting Started

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

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

API

List of currently available permissions

enum Permission {
  // Microphone
  RecordAudio,

  // Camera
  Camera,

  // Read External Storage (Android)
  ReadExternalStorage

  // Write External Storage (Android)
  WriteExternalStorage,

  // Access Coarse Location (Android) / When In Use iOS
  AccessCoarseLocation,

  // Access Fine Location (Android) / When In Use iOS
  AccessFineLocation,

  // Access Fine Location (Android) / When In Use iOS
  WhenInUseLocation,

  // Access Fine Location (Android) / Always Location iOS
  AlwaysLocation

  // Write contacts (Android) / Contacts iOS
  WriteContacts

  // Read contacts (Android) / Contacts iOS
  ReadContacts
}
/// Permissions status enum (iOS)
enum PermissionStatus { notDetermined, restricted, denied, authorized }

Methods

  /// Check a [permission] and return a [Future] with the result
  static Future<bool> checkPermission(Permission permission);

  /// Request a [permission] and return a [Future] with the result
  static Future<bool> requestPermission(Permission permission);

  /// Open app settings on Android and iOS
  static Future<bool> openSettings();
  
  /// Get iOs permission status 
  static Future<PermissionStatus> getPermissionStatus(Permission permission)

0.1.1

  • won't be updating anything soon, don't use this!!!

0.1.1

  • Updated podspec to automatically set the swift version

0.1.0

  • Changed ios code to Swift 3.3.

0.0.1

  • initial release.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:permissions/permissions.dart';

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

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

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

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await Permissions.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Plugin example app'),
        ),
        body: new Center(
          child: new Column(children: <Widget>[
            new Text('Running on: $_platformVersion\n'),
            new DropdownButton(items: _getDropDownItems(), value: permission, onChanged: onDropDownChanged),
            new RaisedButton(onPressed: checkPermission, child: new Text("Check permission")),
            new RaisedButton(onPressed: requestPermission, child: new Text("Request permission")),
            new RaisedButton(onPressed: getPermissionStatus, child: new Text("Get permission status")),
            new RaisedButton(onPressed: Permissions.openSettings, child: new Text("Open settings"))
          ]),
        ),
      ),
    );
  }

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

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

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

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

  List<DropdownMenuItem<Permission>>_getDropDownItems() {
    List<DropdownMenuItem<Permission>> items = new List();
    Permission.values.forEach((permission) {
      var item  = new DropdownMenuItem(child: new Text(getPermissionString(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:
  permissions: ^0.1.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or 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:permissions/permissions.dart';
  
Version Uploaded Documentation Archive
0.1.2 Jun 28, 2018 Go to the documentation of permissions 0.1.2 Download permissions 0.1.2 archive
0.1.1 Jun 28, 2018 Go to the documentation of permissions 0.1.1 Download permissions 0.1.1 archive
0.1.0 Jun 28, 2018 Go to the documentation of permissions 0.1.0 Download permissions 0.1.0 archive
0.0.1 Jun 28, 2018 Go to the documentation of permissions 0.0.1 Download permissions 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
70
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
35
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <2.0.0