getChildren static method

List<Widget> getChildren(
  1. BuildContext context, {
  2. required KnowledgePanelElement panelElement,
  3. required Product product,
  4. required bool onboardingMode,
  5. required bool simplified,
})

Implementation

static List<Widget> getChildren(
  BuildContext context, {
  required KnowledgePanelElement panelElement,
  required Product product,
  required bool onboardingMode,
  required bool simplified,
}) {
  final String? panelId = panelElement.panelElement?.panelId;
  final KnowledgePanel? rootPanel = panelId == null
      ? null
      : getKnowledgePanel(product, panelId);
  final List<Widget> children = <Widget>[];
  if (rootPanel != null) {
    children.add(
      KnowledgePanelTitle(
        title: rootPanel.titleElement!.title ?? '',
        topics: rootPanel.topics,
      ),
    );
    final List<KnowledgePanelElement>? elements =
        panelId == _simplifiedHealthCardId
        ? _getSimplifiedHealthCardElements(product, rootPanel)
        : rootPanel.elements;
    if (elements != null) {
      for (int i = 0; i < elements.length; i++) {
        final KnowledgePanelElement element = elements[i];
        final Widget? widget = getElementWidget(
          knowledgePanelElement: element,
          product: product,
          isInitiallyExpanded: false,
          isClickable: true,
          isTextSelectable: !onboardingMode,
          position: i,
          simplified: simplified,
        );
        if (widget != null) {
          children.add(widget);
        }
      }
    }
  }
  if (!onboardingMode) {
    if (panelId == _healthCardId || panelId == _simplifiedHealthCardId) {
      final bool nutritionAddOrUpdate =
          product.statesTags?.contains(
            ProductState.NUTRITION_FACTS_COMPLETED.toBeCompletedTag,
          ) ??
          false;
      if (nutritionAddOrUpdate) {
        if (AddNutritionButton.acceptsNutritionFacts(product)) {
          children.add(_getPaddedButton(AddNutritionButton(product)));
        }
      }

      final bool needEditIngredients =
          context.read<UserPreferences>().getFlag(
            UserPreferencesDevMode.userPreferencesFlagEditIngredients,
          ) ??
          false;
      if ((product.ingredientsText == null ||
              product.ingredientsText!.isEmpty) &&
          needEditIngredients) {
        // When the flag is removed, this should be the following:
        // if (product.statesTags?.contains('en:ingredients-to-be-completed') ?? false) {
        children.add(
          _getPaddedButton(
            AddOcrButton(
              product: product,
              editor: ProductFieldOcrIngredientEditor(),
            ),
          ),
        );
      }
    }
  }
  if (children.isEmpty) {
    Logs.e(
      'Unexpected empty panel data for product "${product.barcode}" and panelId "$panelId"',
    );
  }
  return children;
}