navigateTo static method

Future<void> navigateTo(
  1. BuildContext context,
  2. ActionModel action, {
  3. Map<String, dynamic>? parameters,
})

Implementation

static Future<void> navigateTo(BuildContext context, ActionModel action,
    {Map<String, dynamic>? parameters}) async {
  if (await action.hasAccess(context)) {
    if (action is FunctionToRun) {
      action.actionToRun();
    } else if (action is GotoPage) {
      BlocProvider.of<AccessBloc>(context).add(
          GotoPageEvent(action.app, action.pageID, parameters: parameters));
    } else if (action is OpenDialog) {
      await Registry.registry()!.openDialog(context,
          app: action.app, id: action.dialogID, parameters: parameters);
      // NAVIGATION-USING-BLOC
      // We should be using this instead: BlocProvider.of<AccessBloc>(context).add(OpenDialogEvent(action.dialogID, parameters: parameters));
    } else if (action is SwitchApp) {
      BlocProvider.of<AccessBloc>(context)
          .add(SwitchAppWithIDEvent(appId: action.toAppID, goHome: true));
    } else if (action is InternalAction) {
      switch (action.internalActionEnum) {
        case InternalActionEnum.login:
          openLoginWidget(context, action.app);
          break;
        case InternalActionEnum.logout:
          BlocProvider.of<AccessBloc>(context)
              .add(LogoutEvent(app: action.app));
          break;
        case InternalActionEnum.goHome:
          BlocProvider.of<AccessBloc>(context).add(GoHome(app: action.app));
          break;
        default:
          return;
      }
    } else {
      for (var i = 0; i < _registeredActionHandlers.length; i++) {
        _registeredActionHandlers[i]
            .navigateTo(context, action, parameters: parameters);
      }
    }
  } else {
    // return Text("no access");
    return;
  }
}