Skip to content

Commit 1260758

Browse files
committed
Release 2.0.0
2 parents bd55850 + 3241f25 commit 1260758

File tree

10 files changed

+62
-51
lines changed

10 files changed

+62
-51
lines changed

.travis.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
matrix:
22
include:
3+
# Job 1) Run analyzer
4+
- os: linux
5+
env:
6+
- SHARD=Analyze
7+
sudo: false
8+
addons:
9+
apt:
10+
# Flutter depends on /usr/lib/x86_64-linux-gnu/libstdc++.so.6 version GLIBCXX_3.4.18
11+
sources:
12+
- ubuntu-toolchain-r-test # if we don't specify this, the libstdc++6 we get is the wrong version
13+
packages:
14+
- libstdc++6
15+
- fonts-droid
16+
before_script:
17+
- git clone https://github.com/flutter/flutter.git $HOME/flutter
18+
- export PATH=$HOME/flutter/bin:$HOME/flutter/bin/cache/dart-sdk/bin:$PATH
19+
- flutter doctor
20+
script:
21+
- flutter analyze
22+
# Job 2) Build the Android axample application (.apk)
323
- os: linux
424
env:
525
- SHARD="Build example apks"
@@ -21,7 +41,7 @@ matrix:
2141
script:
2242
- cd ./example
2343
- flutter build apk
24-
# Job 2) Build example IPAs
44+
# Job 3) Build the iOS example Applications (.ipa)
2545
- os: osx
2646
env:
2747
- SHARD="Build example ipas"

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.0
2+
3+
* Make methods non static so users can create an instance or override
4+
15
## 1.0.1
26

37
* Converted the plugin into a library so that developers don't have to import additional files;

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ To use this plugin, add `permission_handler` as a [dependency in your pubspec.ya
2222

2323
```yaml
2424
dependencies:
25-
permission_handler: '^1.0.1'
25+
permission_handler: '^2.0.0'
2626
```
2727
2828
> **NOTE:** There's a known issue with integrating plugins that use Swift into a Flutter project created with the Objective-C template. See issue [Flutter#16049](https://github.com/flutter/flutter/issues/16049) for help on integration.
@@ -34,31 +34,31 @@ dependencies:
3434
``` dart
3535
import 'package:permission_handler/permission_handler.dart';
3636

37-
Map<PermissionGroup, PermissionStatus> permissions = await PermissionHandler.requestPermissions([PermissionGroup.contacts]);
37+
Map<PermissionGroup, PermissionStatus> permissions = await PermissionHandler().requestPermissions([PermissionGroup.contacts]);
3838
```
3939

4040
### Checking permission
4141

4242
``` dart
4343
import 'package:permission_handler/permission_handler.dart';
4444
45-
PermissionStatus permission = await PermissionHandler.checkPermissionStatus(PermissionGroup.contacts);
45+
PermissionStatus permission = await PermissionHandler().checkPermissionStatus(PermissionGroup.contacts);
4646
```
4747

4848
### Open app settings
4949

5050
``` dart
5151
import 'package:permission_handler/permission_handler.dart';
5252
53-
bool isOpened = await PermissionHandler.openAppSettings();
53+
bool isOpened = await PermissionHandler().openAppSettings();
5454
```
5555

5656
### Show a rationale for requesting permission (Android only)
5757

5858
``` dart
5959
import 'package:permission_handler/permission_handler.dart';
6060
61-
bool isShown = await PermissionHandler.shouldShowRequestPermissionRationale(PermissionGroup.contacts);
61+
bool isShown = await PermissionHandler().shouldShowRequestPermissionRationale(PermissionGroup.contacts);
6262
```
6363

6464
This will always return `false` on iOS.

example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
}
77

88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.1.3'
9+
classpath 'com.android.tools.build:gradle:3.1.4'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111
}
1212
}

example/lib/main.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MyApp extends StatelessWidget {
1616
IconButton(
1717
icon: const Icon(Icons.settings),
1818
onPressed: () {
19-
PermissionHandler.openAppSettings();
19+
PermissionHandler().openAppSettings();
2020
},
2121
)
2222
],
@@ -69,7 +69,7 @@ class _PermissionState extends State<PermissionWidget> {
6969

7070
void _listenForPermissionStatus() async {
7171
final PermissionStatus status =
72-
await PermissionHandler.checkPermissionStatus(_permissionGroup);
72+
await PermissionHandler().checkPermissionStatus(_permissionGroup);
7373

7474
setState(() {
7575
_permissionStatus = status;
@@ -104,7 +104,7 @@ class _PermissionState extends State<PermissionWidget> {
104104
void requestPermission(PermissionGroup permission) async {
105105
final List<PermissionGroup> permissions = <PermissionGroup>[permission];
106106
final Map<PermissionGroup, PermissionStatus> permissionRequestResult =
107-
await PermissionHandler.requestPermissions(permissions);
107+
await PermissionHandler().requestPermissions(permissions);
108108

109109
setState(() {
110110
_permissionStatus = permissionRequestResult[permission];

example/pubspec.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ dependencies:
1010
cupertino_icons: ^0.1.2
1111

1212
dev_dependencies:
13-
flutter_test:
14-
sdk: flutter
15-
1613
permission_handler:
1714
path: ../
1815

example/test/widget_test.dart

Lines changed: 0 additions & 25 deletions
This file was deleted.

ios/permission_handler.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
Pod::Spec.new do |s|
55
s.name = 'permission_handler'
6-
s.version = '1.0.1'
6+
s.version = '2.0.0'
77
s.summary = 'Permission plugin for Flutter.'
88
s.description = <<-DESC
99
Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.

lib/permission_handler.dart

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,34 @@ import 'dart:convert';
55
import 'dart:io';
66

77
import 'package:flutter/services.dart';
8+
import 'package:meta/meta.dart';
89

910
part 'package:permission_handler/permission_enums.dart';
1011
part 'package:permission_handler/utils/codec.dart';
1112

1213
/// Provides a cross-platform (iOS, Android) API to request and check permissions.
1314
class PermissionHandler {
14-
static const MethodChannel _channel =
15-
const MethodChannel('flutter.baseflow.com/permissions/methods');
15+
factory PermissionHandler() {
16+
if (_instance == null) {
17+
const MethodChannel methodChannel =
18+
const MethodChannel('flutter.baseflow.com/permissions/methods');
19+
20+
_instance = new PermissionHandler.private(methodChannel);
21+
}
22+
return _instance;
23+
}
24+
25+
@visibleForTesting
26+
PermissionHandler.private(this._methodChannel);
27+
28+
static PermissionHandler _instance;
29+
30+
final MethodChannel _methodChannel;
1631

1732
/// Returns a [Future] containing the current permission status for the supplied [PermissionGroup].
18-
static Future<PermissionStatus> checkPermissionStatus(
33+
Future<PermissionStatus> checkPermissionStatus(
1934
PermissionGroup permission) async {
20-
final dynamic status = await _channel.invokeMethod(
35+
final dynamic status = await _methodChannel.invokeMethod(
2136
'checkPermissionStatus', Codec.encodePermissionGroup(permission));
2237

2338
return Codec.decodePermissionStatus(status);
@@ -26,19 +41,19 @@ class PermissionHandler {
2641
/// Open the App settings page.
2742
///
2843
/// Returns [true] if the app settings page could be opened, otherwise [false] is returned.
29-
static Future<bool> openAppSettings() async {
30-
final bool hasOpened = await _channel.invokeMethod('openAppSettings');
44+
Future<bool> openAppSettings() async {
45+
final bool hasOpened = await _methodChannel.invokeMethod('openAppSettings');
3146
return hasOpened;
3247
}
3348

3449
/// Request the user for access to the supplied list of permissiongroups.
3550
///
3651
/// Returns a [Map] containing the status per requested permissiongroup.
37-
static Future<Map<PermissionGroup, PermissionStatus>> requestPermissions(
52+
Future<Map<PermissionGroup, PermissionStatus>> requestPermissions(
3853
List<PermissionGroup> permissions) async {
3954
final String jsonData = Codec.encodePermissionGroups(permissions);
4055
final dynamic status =
41-
await _channel.invokeMethod('requestPermissions', jsonData);
56+
await _methodChannel.invokeMethod('requestPermissions', jsonData);
4257

4358
return Codec.decodePermissionRequestResult(status);
4459
}
@@ -47,13 +62,13 @@ class PermissionHandler {
4762
///
4863
/// This method is only implemented on Android, calling this on iOS always
4964
/// returns [false].
50-
static Future<bool> shouldShowRequestPermissionRationale(
65+
Future<bool> shouldShowRequestPermissionRationale(
5166
PermissionGroup permission) async {
5267
if (!Platform.isAndroid) {
5368
return false;
5469
}
5570

56-
final bool shouldShowRationale = await _channel.invokeMethod(
71+
final bool shouldShowRationale = await _methodChannel.invokeMethod(
5772
'shouldShowRequestPermissionRationale',
5873
Codec.encodePermissionGroup(permission));
5974

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: permission_handler
22
description: Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
3-
version: 1.0.1
3+
version: 2.0.0
44
author: Baseflow <hello@baseflow.com>
55
homepage: https://github.com/baseflowit/flutter-permission-handler
66

@@ -18,7 +18,7 @@ flutter:
1818
pluginClass: PermissionHandlerPlugin
1919

2020
environment:
21-
sdk: ">=2.0.0-dev.58.0 <3.0.0"
21+
sdk: ">=2.0.0-dev.68.0 <3.0.0"
2222

2323
# To add assets to your plugin package, add an assets section, like this:
2424
# assets:

0 commit comments

Comments
 (0)