AuthGuard class

Route protection component

Wraps protected routes to ensure only authenticated users can access them. Redirects unauthenticated users to a specified route.

AuthGuard(
  redirectTo: '/login',
  child: DashboardScreen(),
)
Inheritance

Constructors

AuthGuard({required Component child, Component? loadingIndicator, String redirectTo = '/login', bool requireAdmin = false, bool isAdmin(dynamic user)?, Key? key})
const

Properties

child Component
The protected content
final
hashCode int
The hash code for this object.
no setterinherited
isAdmin bool Function(dynamic user)?
Callback to check if user has admin privileges If not provided, always returns false for requireAdmin
final
key Key?
Controls how one component replaces another component in the tree.
finalinherited
loadingIndicator Component?
Custom loading indicator (shown while auth state is loading)
final
redirectTo String
Route to redirect to if not authenticated
final
requireAdmin bool
Whether this route requires admin privileges
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

build(BuildContext context) Component
Describes the part of the user interface represented by this component.
override
createElement() Element
Creates a StatelessElement to manage this component's location in the tree.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
shouldRebuild(covariant Component newComponent) bool
Implement this method to determine whether a rebuild can be skipped.
inherited
toString() String
A string representation of this object.
inherited

Operators

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