refreshRelations static method

Future<PageModel> refreshRelations(
  1. PageModel model
)

Implementation

static Future<PageModel> refreshRelations(PageModel model) async {
  AppBarModel? appBarHolder;
  if (model.appBar != null) {
    try {
      await appBarRepository(appId: model.appId)!
          .get(model.appBar!.documentID)
          .then((val) {
        appBarHolder = val;
      }).catchError((error) {});
    } catch (_) {}
  }

  DrawerModel? drawerHolder;
  if (model.drawer != null) {
    try {
      await drawerRepository(appId: model.appId)!
          .get(model.drawer!.documentID)
          .then((val) {
        drawerHolder = val;
      }).catchError((error) {});
    } catch (_) {}
  }

  DrawerModel? endDrawerHolder;
  if (model.endDrawer != null) {
    try {
      await drawerRepository(appId: model.appId)!
          .get(model.endDrawer!.documentID)
          .then((val) {
        endDrawerHolder = val;
      }).catchError((error) {});
    } catch (_) {}
  }

  HomeMenuModel? homeMenuHolder;
  if (model.homeMenu != null) {
    try {
      await homeMenuRepository(appId: model.appId)!
          .get(model.homeMenu!.documentID)
          .then((val) {
        homeMenuHolder = val;
      }).catchError((error) {});
    } catch (_) {}
  }

  GridViewModel? gridViewHolder;
  if (model.gridView != null) {
    try {
      await gridViewRepository(appId: model.appId)!
          .get(model.gridView!.documentID)
          .then((val) {
        gridViewHolder = val;
      }).catchError((error) {});
    } catch (_) {}
  }

  List<BodyComponentModel>? bodyComponentsHolder;
  if (model.bodyComponents != null) {
    bodyComponentsHolder = List<BodyComponentModel>.from(
            await Future.wait(model.bodyComponents!.map((element) async {
      return await BodyComponentCache.refreshRelations(element);
    })))
        .toList();
  }

  return model.copyWith(
    appBar: appBarHolder,
    drawer: drawerHolder,
    endDrawer: endDrawerHolder,
    homeMenu: homeMenuHolder,
    gridView: gridViewHolder,
    bodyComponents: bodyComponentsHolder,
  );
}