Authorization policies and feature flags for Flutter.
Define who can do what with policies, toggle functionality with feature flags, and wire both into your UI with declarative widgets. Works with vanilla Flutter, Provider, Riverpod, Bloc, and GetX.
-
Policy-based authorization —
view,create,update,delete, and custom abilities per model - Feature flags — sync, async, observable, rollout percentage, and runtime overrides
-
Declarative widgets —
Can,Cannot,FeatureGuard, andBuildContextextensions - Hooks — global before/after interceptors for admin bypasses and audit logging
-
Code generation — auto-register policies and features with
build_runner - State management adapters — Provider, Riverpod, Bloc, GetX
-
Pure Dart core —
flutter_gate_corehas no Flutter dependency
| Package | Description |
|---|---|
flutter_gate_core |
Core engine (pure Dart) |
flutter_gate |
Flutter widgets and extensions |
flutter_gate_provider |
Provider adapter |
flutter_gate_riverpod |
Riverpod adapter |
flutter_gate_bloc |
Bloc/Cubit adapter |
flutter_gate_getx |
GetX adapter |
flutter_gate_generator |
build_runner code generation |
dependencies:
flutter_gate: ^0.1.1Optional adapters and generator:
dependencies:
flutter_gate_riverpod: ^0.1.1
dev_dependencies:
flutter_gate_generator: ^0.1.1
build_runner: ^2.4.01. Register policies and features at startup:
import 'package:flutter_gate/flutter_gate.dart';
void main() {
gate.policy<Post>(() => PostPolicy());
gate.define(const DarkModeFeature());
runApp(const MyApp());
}2. Define a policy:
class PostPolicy extends Policy {
@override
PolicyResponse update(dynamic user, dynamic model) {
final post = model as Post;
return PolicyResponse.fromBool(user == post.authorId);
}
}3. Guard UI with Can:
Can(
ability: 'update',
user: currentUserId,
model: post,
child: IconButton(icon: Icon(Icons.edit), onPressed: onEdit),
)4. Toggle features with FeatureGuard:
FeatureGuard<DarkModeFeature>(
child: DarkThemeSettings(),
fallback: SizedBox.shrink(),
)See the full example app for end-to-end usage.
| Guide | Topics |
|---|---|
| Getting started | Install, bootstrap, first policy & feature |
| Policies | Abilities, responses, scoped context |
| Feature flags | Sync, async, rollout, overrides |
| Widgets |
Can, FeatureGuard, extensions |
| Hooks | Before/after authorization interceptors |
| Code generation |
@PolicyFor, @GateFeature, build_runner |
| State management | Provider, Riverpod, Bloc, GetX |
| Testing | Override gate, widget tests |
# Install melos
dart pub global activate melos
# Bootstrap all packages
melos bootstrap
# Analyze and test
melos run analyze
melos run testMIT — see LICENSE.