OnAuthBuilder<T, P> constructor
OnAuthBuilder<T, P> ({
- Key? key,
- required InjectedAuth<
T, P> listenTo, - required Widget onUnsigned(),
- required Widget onSigned(),
- Widget onInitialWaiting()?,
- Widget onWaiting()?,
- SideEffects<
T> ? sideEffects, - String? debugPrintWhenRebuild,
Listen to an InjectedAuth and define the appropriate view for each case
Implementation
OnAuthBuilder({
Key? key,
required this.listenTo,
required this.onUnsigned,
required this.onSigned,
this.onInitialWaiting,
this.onWaiting,
this.useRouteNavigation = false,
SideEffects<T>? sideEffects,
this.navigatorKey,
String? debugPrintWhenRebuild,
}) : super(
key: key,
observers: (context) {
NavigatorState? navigatorState;
if (navigatorKey == null && useRouteNavigation == true) {
navigatorState = RM.navigate.navigatorKey.currentState;
} else if (navigatorKey != null) {
navigatorState = navigatorKey.currentState;
}
if (navigatorState != null) {
(listenTo as ReactiveModelImp).initialize();
// ignore: unused_result
listenTo.addObserver(
isSideEffects: true,
listener: (rm) {
if (!rm.hasData) return;
navigatorState!.pushAndRemoveUntil(
MaterialPageRoute(
builder: (_) {
return (listenTo as InjectedAuthImp).isSigned
? onSigned()
: onUnsigned();
},
),
(route) => false,
);
},
shouldAutoClean: false,
);
}
return [listenTo as InjectedAuthImp];
},
debugPrintWhenRebuild: debugPrintWhenRebuild,
sideEffects: sideEffects,
shouldRebuild: (old, current) {
if (navigatorKey != null || useRouteNavigation) {
return false;
}
return true;
},
builder: null,
);