fromEntityPlus static method

Future<FeedMenuModel?> fromEntityPlus(
  1. String documentID,
  2. FeedMenuEntity? entity, {
  3. String? appId,
})

Implementation

static Future<FeedMenuModel?> fromEntityPlus(
    String documentID, FeedMenuEntity? entity,
    {String? appId}) async {
  if (entity == null) return null;

  FeedFrontModel? feedFrontHolder;
  if (entity.feedFrontId != null) {
    try {
      feedFrontHolder =
          await feedFrontRepository(appId: appId)!.get(entity.feedFrontId);
    } on Exception catch (e) {
      print('Error whilst trying to initialise feedFront');
      print(
          'Error whilst retrieving feedFront with id ${entity.feedFrontId}');
      print('Exception: $e');
    }
  }

  var counter = 0;
  return FeedMenuModel(
    documentID: documentID,
    appId: entity.appId ?? '',
    description: entity.description,
    bodyComponentsCurrentMember: entity.bodyComponentsCurrentMember == null
        ? null
        : List<LabelledBodyComponentModel>.from(
            await Future.wait(entity.bodyComponentsCurrentMember!.map((item) {
            counter++;
            return LabelledBodyComponentModel.fromEntityPlus(
                counter.toString(), item,
                appId: appId);
          }).toList())),
    bodyComponentsOtherMember: entity.bodyComponentsOtherMember == null
        ? null
        : List<LabelledBodyComponentModel>.from(
            await Future.wait(entity.bodyComponentsOtherMember!.map((item) {
            counter++;
            return LabelledBodyComponentModel.fromEntityPlus(
                counter.toString(), item,
                appId: appId);
          }).toList())),
    itemColor: await RgbModel.fromEntityPlus(entity.itemColor, appId: appId),
    selectedItemColor:
        await RgbModel.fromEntityPlus(entity.selectedItemColor, appId: appId),
    backgroundOverride: await BackgroundModel.fromEntityPlus(
        entity.backgroundOverride,
        appId: appId),
    feedFront: feedFrontHolder,
    conditions: await StorageConditionsModel.fromEntityPlus(entity.conditions,
        appId: appId),
  );
}