forked from Baseflow/flutter-permission-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support web implementation of permission_handler (Baseflow#1121)
* added integration tests * added basic integration tests * updated integration tests * continued integration tests * added unit test file * Move each permission request to its own private method * Add unit tests and fake web permission handler plugin * added unit tests for camera and microphone * Updated documentation files * Create superclass web_handler.dart * Use OOP delegation pattern for web_handler * Change web_handler.dart to web_delegate.dart * Make WebDelegate class initialization lazy * Create unit test for each method and permission * removed redundant integration_test module * remove redundant test_driver module * Revert unneeded files and add api docs * Add geolocation to web permission_handler * Formatted web_delegate.dart * Avoid swallowing request permission exception * Replace UnimplementedError with UnsupportedError for requestPermissions method Co-authored-by: Maurits van Beusekom <[email protected]> * Make WebDelegate instance variables private --------- Co-authored-by: Victor Sanni <[email protected]> Co-authored-by: Maurits van Beusekom <[email protected]>
- Loading branch information
1 parent
4026813
commit a021685
Showing
28 changed files
with
2,896 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: 796c8ef79279f9c774545b3771238c3098dbefab | ||
channel: stable | ||
|
||
project_type: package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.1.0 | ||
|
||
* Adds an initial implementation of Web support for the permission_handler plugin with camera, notifications, and microphone permissions available. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Baseflow | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# permission_handler_web | ||
|
||
[![pub package](https://img.shields.io/pub/v/permission_handler_web.svg)](https://pub.dartlang.org/packages/permission_handler_web) ![Build status](https://github.com/Baseflow/flutter-permission-handler/workflows/permission_handler_web/badge.svg?branch=master) [![style: flutter lints](https://img.shields.io/badge/style-flutter_lints-40c4ff.svg)](https://pub.dev/packages/flutter_lints) | ||
|
||
The official web implementation of the [permission_handler](https://pub.dev/packages/permission_handler) plugin by [Baseflow](https://baseflow.com). | ||
|
||
## Usage | ||
|
||
This is the officially endorsed web implementation of the permission_handler plugin. This means it will automatically be added to your dependencies when you depend on `permission_handler` in your applications pubspec.yaml. | ||
|
||
More detailed instructions on using the API can be found in the [README.md](../permission_handler/README.md) of the [permission_handler](https://pub.dev/packages/permission_handler) package. | ||
|
||
## Issues | ||
|
||
Please file any issues, bugs or feature requests as an issue on our [GitHub](https://github.com/Baseflow/flutter-permission-handler/issues) page. Commercial support is available, you can contact us at <[email protected]>. | ||
|
||
## Want to contribute | ||
|
||
If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our [contribution guide](../CONTRIBUTING.md) and send us your [pull request](https://github.com/Baseflow/flutter-permission-handler/pulls). | ||
|
||
## Author | ||
|
||
This permission_handler plugin for Flutter is developed by [Baseflow](https://baseflow.com). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
**/ios/Flutter/.last_build_id | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
|
||
# Symbolication related | ||
app.*.symbols | ||
|
||
# Obfuscation related | ||
app.*.map.json | ||
|
||
# Android Studio will place build artifacts here | ||
/android/app/debug | ||
/android/app/profile | ||
/android/app/release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled. | ||
|
||
version: | ||
revision: 796c8ef79279f9c774545b3771238c3098dbefab | ||
channel: stable | ||
|
||
project_type: app | ||
|
||
# Tracks metadata for the flutter migrate command | ||
migration: | ||
platforms: | ||
- platform: root | ||
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab | ||
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab | ||
- platform: android | ||
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab | ||
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab | ||
- platform: ios | ||
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab | ||
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab | ||
- platform: linux | ||
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab | ||
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab | ||
- platform: macos | ||
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab | ||
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab | ||
- platform: web | ||
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab | ||
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab | ||
- platform: windows | ||
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab | ||
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab | ||
|
||
# User provided section | ||
|
||
# List of Local paths (relative to this file) that should be | ||
# ignored by the migrate tool. | ||
# | ||
# Files that are not part of the templates will be ignored by default. | ||
unmanaged_files: | ||
- 'lib/main.dart' | ||
- 'ios/Runner.xcodeproj/project.pbxproj' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# example | ||
|
||
A new Flutter project. | ||
|
||
## Getting Started | ||
|
||
This project is a starting point for a Flutter application. | ||
|
||
A few resources to get you started if this is your first Flutter project: | ||
|
||
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) | ||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) | ||
|
||
For help getting started with Flutter development, view the | ||
[online documentation](https://docs.flutter.dev/), which offers tutorials, | ||
samples, guidance on mobile development, and a full API reference. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import 'package:baseflow_plugin_template/baseflow_plugin_template.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:permission_handler_platform_interface/permission_handler_platform_interface.dart'; | ||
|
||
void main() { | ||
runApp(BaseflowPluginExample( | ||
pluginName: 'Permission Handler', | ||
githubURL: 'https://github.com/Baseflow/flutter-permission-handler', | ||
pubDevURL: 'https://pub.dev/packages/permission_handler', | ||
pages: [PermissionHandlerWidget.createPage()])); | ||
} | ||
|
||
///Defines the main theme color | ||
final MaterialColor themeMaterialColor = | ||
BaseflowPluginExample.createMaterialColor( | ||
const Color.fromRGBO(48, 49, 60, 1)); | ||
|
||
/// A Flutter application demonstrating the functionality of this plugin | ||
class PermissionHandlerWidget extends StatefulWidget { | ||
/// Create a page containing the functionality of this plugin | ||
static ExamplePage createPage() { | ||
return ExamplePage( | ||
Icons.location_on, (context) => PermissionHandlerWidget()); | ||
} | ||
|
||
@override | ||
_PermissionHandlerWidgetState createState() => | ||
_PermissionHandlerWidgetState(); | ||
} | ||
|
||
class _PermissionHandlerWidgetState extends State<PermissionHandlerWidget> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Center( | ||
child: ListView( | ||
children: Permission.values | ||
.where((permission) { | ||
return permission != Permission.unknown && | ||
permission != Permission.mediaLibrary && | ||
permission != Permission.photos && | ||
permission != Permission.photosAddOnly && | ||
permission != Permission.reminders && | ||
permission != Permission.appTrackingTransparency && | ||
permission != Permission.criticalAlerts; | ||
}) | ||
.map((permission) => PermissionWidget(permission)) | ||
.toList()), | ||
); | ||
} | ||
} | ||
|
||
/// Permission widget containing information about the passed [Permission] | ||
class PermissionWidget extends StatefulWidget { | ||
/// Constructs a [PermissionWidget] for the supplied [Permission] | ||
const PermissionWidget(this._permission); | ||
|
||
final Permission _permission; | ||
|
||
@override | ||
_PermissionState createState() => _PermissionState(_permission); | ||
} | ||
|
||
class _PermissionState extends State<PermissionWidget> { | ||
_PermissionState(this._permission); | ||
|
||
final Permission _permission; | ||
final PermissionHandlerPlatform _permissionHandler = | ||
PermissionHandlerPlatform.instance; | ||
PermissionStatus _permissionStatus = PermissionStatus.denied; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
_listenForPermissionStatus(); | ||
} | ||
|
||
void _listenForPermissionStatus() async { | ||
final status = await _permissionHandler.checkPermissionStatus(_permission); | ||
setState(() => _permissionStatus = status); | ||
} | ||
|
||
Color getPermissionColor() { | ||
switch (_permissionStatus) { | ||
case PermissionStatus.denied: | ||
return Colors.red; | ||
case PermissionStatus.granted: | ||
return Colors.green; | ||
case PermissionStatus.limited: | ||
return Colors.orange; | ||
default: | ||
return Colors.grey; | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ListTile( | ||
title: Text( | ||
_permission.toString(), | ||
style: Theme.of(context).textTheme.bodyLarge, | ||
), | ||
subtitle: Text( | ||
_permissionStatus.toString(), | ||
style: TextStyle(color: getPermissionColor()), | ||
), | ||
trailing: (_permission is PermissionWithService) | ||
? IconButton( | ||
icon: const Icon( | ||
Icons.info, | ||
color: Colors.white, | ||
), | ||
onPressed: () { | ||
checkServiceStatus( | ||
context, _permission as PermissionWithService); | ||
}) | ||
: null, | ||
onTap: () { | ||
requestPermission(_permission); | ||
}, | ||
); | ||
} | ||
|
||
void checkServiceStatus( | ||
BuildContext context, PermissionWithService permission) async { | ||
ScaffoldMessenger.of(context).showSnackBar(SnackBar( | ||
content: Text( | ||
(await _permissionHandler.checkServiceStatus(permission)).toString()), | ||
)); | ||
} | ||
|
||
Future<void> requestPermission(Permission permission) async { | ||
final status = await _permissionHandler.requestPermissions([permission]); | ||
|
||
setState(() { | ||
print(status); | ||
_permissionStatus = status[permission] ?? PermissionStatus.denied; | ||
print(_permissionStatus); | ||
}); | ||
} | ||
} |
Oops, something went wrong.