A simple package to control widgets based on user privileges. Choose what users can interact based on plan, roles or any other condition.
name: your_flutter_app
dependencies:
flutter:
sdk: flutter
grant:
class CanChat extends PermissionBase {}
class CanCreateTeams extends PermissionBase {}
...
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: _navigatorKey,
title: 'Flutter Demo',
home: GrantAccess(
child: YourApp()
),
);
}
}
From anywhere in your app
...
GrantAccess.storeOf(context).updatePermissions(permissions);
Center(
child: CanSee(
permissions: [CanChat()],
child: ChatButton()
),
)
CanSee
will show the child
only if user's current permission matches permissions
.
Center(
child: CanConsume(
permissions: [CanCreateTeams()],
builder: (context, bool allowed){
return allowed ? CreateTeamButton() : OtherWidget()
}
),
)
CanConsume
gives a bool allowed
using a builder
.