permissions_plugin 1.1.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 81

Permissions Plugin #

Build version

Plugin for permission managment on runtime.

Getting Started #

Installing #

Use this package as a library #

1. Depend on it Add this to your package's pubspec.yaml file:

dependencies:
  permissions_plugin: ^1.1.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:permissions_plugin/permissions_plugin.dart';

New Features! #

  • Request ignore battery optimization
  • check status ignore battery optimization

You can also:

  • Request permission on runtime
  • Check status permission on runtime
Request permission #
import 'package:permissions_plugin/permissions_plugin.dart';

Map<Permission, PermissionState> permission = await PermissionsPlugin
    .requestPermissions([
        Permission.ACCESS_FINE_LOCATION,
        Permission.ACCESS_COARSE_LOCATION,
        Permission.READ_PHONE_STATE
    ]);
Check status permission #
import 'package:permissions_plugin/permissions_plugin.dart';

Map<Permission, PermissionState> permission = await PermissionsPlugin
    .checkPermissions([
      Permission.ACCESS_FINE_LOCATION,
      Permission.ACCESS_COARSE_LOCATION,
      Permission.READ_PHONE_STATE
    ]);
Request ignore battery optimization #
import 'package:permissions_plugin/permissions_plugin.dart';

final PermissionState resBattery = await PermissionsPlugin
    .requestIgnoreBatteryOptimization;
Check status ignore battery optimization #
import 'package:permissions_plugin/permissions_plugin.dart';

final PermissionState status = await PermissionsPlugin
    .isIgnoreBatteryOptimization;

List Permissions #

Current suport Android only

enum Permission {
  READ_CALENDAR,
  WRITE_CALENDAR,
  READ_CALL_LOG,
  WRITE_CALL_LOG,
  PROCESS_OUTGOING_CALLS,
  CAMERA,
  READ_CONTACTS,
  WRITE_CONTACTS,
  GET_ACCOUNTS,
  ACCESS_FINE_LOCATION,
  ACCESS_COARSE_LOCATION,
  RECORD_AUDIO,
  READ_PHONE_STATE,
  CALL_PHONE,
  ADD_VOICEMAIL,
  USE_SIP,
  BODY_SENSORS,
  SEND_SMS,
  RECEIVE_SMS,
  READ_SMS,
  RECEIVE_WAP_PUSH,
  RECEIVE_MMS,
  READ_EXTERNAL_STORAGE,
  WRITE_EXTERNAL_STORAGE
}

List Permissions state #

enum PermissionState {
  GRANTED,
  DENIED,
  UNKNOWN
}

### Platform Support

OSMin Version
AndroidminSdkVersion 16
IOSsoon

License #

MIT

AUTHOR #

This plugin is developed, Free Software, by Kevin Caicedo

1.1.4 #

  • Request ignore battery optimization
  • check status ignore battery optimization
  • Fix bugs

1.0.0 #

  • Request permission on runtime
  • Check status permission on runtime

0.0.1 #

  • TODO: Describe initial release.

example/README.md

permissions_plugin_example #

Demonstrates how to use the permissions_plugin.

Example #

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

import 'package:permissions_plugin/permissions_plugin.dart';


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

class MyInitApp extends StatelessWidget {
  // This widget is the root of your application.

  @override
  Widget build(BuildContext context) {
    //initPlatformState();
    return MaterialApp(
      title: 'Ecample permission',
      //showPerformanceOverlay: true,
      //showSemanticsDebugger: true,
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.green,
      ),
      initialRoute: '/',
      routes: {
        '/': (context) => MyApp(),
        '/login': (context) => MyApp()
      },
      //home: MyApp(),
    );
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    checkPermissions(context);

    return Scaffold(
      appBar: AppBar(),
    );
  }

  Future<void> checkPermissions(BuildContext context) async {

    final PermissionState aks = await PermissionsPlugin.isIgnoreBatteryOptimization;

    PermissionState resBattery;
    if(aks != PermissionState.GRANTED)
      resBattery = await PermissionsPlugin.requestIgnoreBatteryOptimization;

    print(resBattery);
    
    Map<Permission, PermissionState> permission = await PermissionsPlugin
        .checkPermissions([
      Permission.ACCESS_FINE_LOCATION,
      Permission.ACCESS_COARSE_LOCATION,
      Permission.READ_PHONE_STATE
    ]);

    if( permission[Permission.ACCESS_FINE_LOCATION] != PermissionState.GRANTED ||
        permission[Permission.ACCESS_COARSE_LOCATION] != PermissionState.GRANTED ||
        permission[Permission.READ_PHONE_STATE] != PermissionState.GRANTED ) {

      try {
        permission = await PermissionsPlugin
            .requestPermissions([
          Permission.ACCESS_FINE_LOCATION,
          Permission.ACCESS_COARSE_LOCATION,
          Permission.READ_PHONE_STATE
        ]);
      } on Exception {
        debugPrint("Error");
      }

      if( permission[Permission.ACCESS_FINE_LOCATION] == PermissionState.GRANTED &&
          permission[Permission.ACCESS_COARSE_LOCATION] == PermissionState.GRANTED &&
          permission[Permission.READ_PHONE_STATE] == PermissionState.GRANTED )
        print("Login ok");
      else
        permissionsDenied(context);

    } else {
      print("Login ok");
    }
  }

  void permissionsDenied(BuildContext context){
    showDialog(context: context, builder: (BuildContext _context) {
      return SimpleDialog(
        title: const Text("Permisos denegados"),
        children: <Widget>[
          Container(
            padding: EdgeInsets.only(left: 30, right: 30, top: 15, bottom: 15),
            child: const Text(
              "Debes conceder todo los permiso para poder usar esta aplicacion",
              style: TextStyle(
                  fontSize: 18,
                  color: Colors.black54
              ),
            ),
          )
        ],
      );
    });
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  permissions_plugin: ^1.1.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:permissions_plugin/permissions_plugin.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
71
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
82
Overall:
Weighted score of the above. [more]
81
Learn more about scoring.

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

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

39 out of 39 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/permissions_plugin.dart.

Run flutter format to format lib/permissions_plugin.dart.

Maintenance suggestions

The package description is too short. (-18 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test