BottomNavBarCreateBloc constructor

BottomNavBarCreateBloc(
  1. String appId,
  2. HomeMenuModel initialiseWithBottomNav
)

Implementation

BottomNavBarCreateBloc(
  this.appId,
  HomeMenuModel initialiseWithBottomNav,
)   : bottomNavModel = deepCopy(appId, initialiseWithBottomNav),
      super(BottomNavBarCreateUninitialised()) {
  on<BottomNavBarCreateEventValidateEvent>((event, emit) {
    // the updates happen on a (deep) copy
    emit(BottomNavBarCreateValidated(deepCopy(appId, event.homeMenuModel)));
  });

  on<BottomNavBarCreateEventApplyChanges>((event, emit) async {
    var theState = state as BottomNavBarCreateInitialised;
    bottomNavModel.menu = theState.homeMenuModel.menu;
    if (event.save) {
      var homeMenu = await homeMenuRepository(appId: bottomNavModel.appId)!
          .get(theState.homeMenuModel.documentID);
      if (homeMenu == null) {
        await homeMenuRepository(appId: bottomNavModel.appId)!
            .add(theState.homeMenuModel);
      } else {
        await homeMenuRepository(appId: bottomNavModel.appId)!
            .update(theState.homeMenuModel);
      }

      var menuDef = await menuDefRepository(appId: bottomNavModel.appId)!
          .get(theState.homeMenuModel.menu!.documentID);
      if (menuDef == null) {
        await menuDefRepository(appId: bottomNavModel.appId)!
            .add(theState.homeMenuModel.menu!);
      } else {
        await menuDefRepository(appId: bottomNavModel.appId)!
            .update(theState.homeMenuModel.menu!);
      }
    }
  });
}