CompositeAccessGate class final

A flexible access gate that evaluates a list of conditions and displays widgets based on the evaluation strategy defined by variant.

Supports both sync and async conditions. Conditions can be evaluated using:

  • CompositeAccessGate (default: all)
  • CompositeAccessGate.any
  • CompositeAccessGate.none
  • CompositeAccessGate.atLeast
  • CompositeAccessGate.builder for full custom rendering

Example

CompositeAccessGate.any(
  conditions: [
    (ctx) => user.hasRole('admin'),
    (ctx) => user.hasPermission('view'),
  ],
  child: Text('Access granted'),
  fallback: Text('Access denied'),
)

Supports onAllow, onDeny, onError callbacks, a debug mode, and async loading state.

Inheritance

Constructors

CompositeAccessGate.new({required List<AccessCondition> conditions, required Widget child, Widget? fallback, Widget? loading, bool debug = false, void onAllow()?, void onDeny()?, void onError(Object error)?, Key? key})
Default constructor: all conditions must return true.
const
CompositeAccessGate.any({required List<AccessCondition> conditions, required Widget child, Widget? fallback, Widget? loading, bool debug = false, void onAllow()?, void onDeny()?, void onError(Object error)?, Key? key})
Requires at least one condition to return true.
const
CompositeAccessGate.atLeast({required List<AccessCondition> conditions, required int? atLeastCount, required Widget child, Widget? fallback, Widget? loading, bool debug = false, void onAllow()?, void onDeny()?, void onError(Object error)?, Key? key})
Requires at least atLeastCount conditions to return true.
const
CompositeAccessGate.builder({required List<AccessCondition> conditions, required AccessGateBuilder? builder, Widget? loading, bool debug = false, void onAllow()?, void onDeny()?, void onError(Object error)?, CompositeVariant variant = CompositeVariant.all, int? atLeastCount, Key? key})
Custom builder constructor. Allows full control over rendering based on access result.
const
CompositeAccessGate.none({required List<AccessCondition> conditions, required Widget child, Widget? fallback, Widget? loading, bool debug = false, void onAllow()?, void onDeny()?, void onError(Object error)?, Key? key})
Requires all conditions to return false.
const

Properties

atLeastCount int?
Used with CompositeVariant.atLeast to define how many true conditions are required.
final
builder AccessGateBuilder?
A custom builder that receives the final access decision.
final
child Widget?
Widget to render if access is granted.
final
conditions List<AccessCondition>
List of conditions to evaluate. Can be synchronous or asynchronous.
final
debug bool
Enables debug logging of evaluation steps.
final
fallback Widget?
Widget to render if access is denied.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
loading Widget?
Widget to render while async conditions are still being evaluated.
final
onAllow → void Function()?
Called once if access is granted.
final
onDeny → void Function()?
Called once if access is denied.
final
onError → void Function(Object error)?
Called if any condition throws an error.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
variant CompositeVariant
Evaluation strategy: all/any/none/atLeast
final

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited