FirebaseAuthRouter class
A router widget that handles Firebase Authentication state changes.
This widget listens to authentication state changes and automatically routes between a login page and home page based on the user's authentication status.
Example usage:
FirebaseAuthRouter(
firebaseAuth: FirebaseAuth.instance,
home: const HomePage(),
loginPage: const LoginPage(),
loadingWidget: const CircularProgressIndicator(),
onLogin: (user) {
// Perform post-login operations
analytics.logLogin();
},
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- FirebaseAuthRouter
Constructors
- FirebaseAuthRouter({required FirebaseAuth firebaseAuth, required Widget home, required Widget loginPage, Key? key, Widget loadingWidget = const Center(child: CircularProgressIndicator()), dynamic onLogin(User)?, dynamic onError(Object error)?, Widget errorBuilder(BuildContext context, Object error)?})
-
Creates a Firebase authentication router.
Firebase authentication state changes are listened to and the appropriate
page is displayed based on the user's authentication status.
const
Properties
- errorBuilder → Widget Function(BuildContext context, Object error)?
-
Builder function to create a custom error widget.
If not provided, a default error widget will be shown with a retry button.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- home → Widget
-
The widget to display when a user is authenticated.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- loadingWidget → Widget
-
The widget to display while waiting for the initial Firebase to establish.
final
- loginPage → Widget
-
The widget to display when no user is authenticated.
final
- onError → dynamic Function(Object error)?
-
Callback triggered when an error occurs during authentication.
The error object is passed as an argument to the callback.
This is not the same as a user failing to authenticate.
final
- onLogin → dynamic Function(User)?
-
Callback triggered when a user is authenticated.
The user object is passed as an argument to the callback.
Useful for things like: analytics, logging, data initialisation, etc.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
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.
override
-
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