https://github.com/karbunkul/flutter_access_control
https://github.com/karbunkul/flutter_access_control
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/karbunkul/flutter_access_control
- Owner: karbunkul
- License: mit
- Created: 2022-05-22T20:54:19.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-07-06T07:21:26.000Z (almost 3 years ago)
- Last Synced: 2023-08-09T13:41:40.341Z (almost 3 years ago)
- Language: Dart
- Size: 350 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# access_control
Check access control via permissions

## Getting started
Add package to your project ```flutter pub add access_control```.
## Usage
Create permission (implements PermissionInterface)
```dart
class DeveloperPermission extends Permission {
final bool developer;
DeveloperPermission(this.developer);
@override
FutureOr request(BuildContext context) {
// You can be use context for get data from InheritedWidget or state
return developer;
}
}
```
Wrap whole page or other widgets
```dart
class DemoPage extends StatefulWidget {
const DemoPage({Key? key}) : super(key: key);
@override
State createState() => _DemoPageState();
}
class _DemoPageState extends State {
var developer = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Access control')),
body: Center(
child: AccessControl.permission(
child: const Text('Developer workspace'),
denied: const Text('Access denied'),
permission: DeveloperPermission(developer),
),
),
floatingActionButton: FloatingActionButton(
child: Icon(
developer ? Icons.person_outline : Icons.bug_report_outlined,
),
onPressed: () => setState(() => developer = !developer),
),
);
}
}
```