getOrCreate method

Future<DrawerModel> getOrCreate()

Implementation

Future<DrawerModel> getOrCreate() async {
  var drawerModel =
      await drawerRepository(appId: app.documentID)!.get(identifier);
  if (drawerModel == null) {
    BackgroundModel? headerBackgroundOverride;
    if (logo != null) {
      headerBackgroundOverride = _drawerHeaderBGOverride(logo);
    }

    drawerModel = DrawerModel(
        documentID: identifier,
        appId: app.documentID,
        name: 'Drawer',
        headerText: '',
        headerBackgroundOverride: headerBackgroundOverride,
        headerHeight: 0,
        popupMenuBackgroundColor: RgbModel(r: 255, g: 0, b: 0, opacity: 1.00),
        menu: await menuDef());

    await drawerRepository(appId: app.documentID)!.add(drawerModel);
  } else {
    // update the logo with the logo provided
    if (logo != null) {
      var headerBackgroundOverride = _drawerHeaderBGOverride(logo);
      await drawerRepository(appId: app.documentID)!.update(drawerModel
          .copyWith(headerBackgroundOverride: headerBackgroundOverride));
    }
  }
  return drawerModel;
}