OnAuthBuilder<T, P> constructor

OnAuthBuilder<T, P>({
  1. Key? key,
  2. required InjectedAuth<T, P> listenTo,
  3. required Widget onUnsigned(),
  4. required Widget onSigned(),
  5. Widget onInitialWaiting()?,
  6. Widget onWaiting()?,
  7. bool useRouteNavigation = false,
  8. SideEffects<T>? sideEffects,
  9. GlobalKey<NavigatorState>? navigatorKey,
  10. 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,
      );