searchTiles method

List<PreferenceTile> searchTiles(
  1. BuildContext context,
  2. UserPreferencesFoodSearchHelper helper
)

Implementation

List<PreferenceTile> searchTiles(
  BuildContext context,
  UserPreferencesFoodSearchHelper helper,
) {
  final List<PreferenceTile> result = <PreferenceTile>[];

  if (group.name != null &&
      (helper.matches(<String?>[group.name, group.warning]))) {
    result.add(
      helper.getPreferenceTile(
        title: group.name!,
        context: context,
        onTapCallback: () async {
          // checks the group name and warning for a match and opens attribute group that holds the search match, e.g. "Allergens" for query "allergens"
          await userPreferences.setActiveAttributeGroup(group.id!);
        },
      ),
    );
  }
  final SmoothColorsThemeExtension theme = context
      .extension<SmoothColorsThemeExtension>();

  final Color backgroundColor = context.lightTheme()
      ? theme.primarySemiDark
      : theme.primaryUltraBlack;

  final List<String> excludedAttributeIds = userPreferences
      .getExcludedAttributeIds();
  for (final Attribute attribute in group.attributes!) {
    if (excludedAttributeIds.contains(attribute.id)) {
      continue;
    }
    if (attribute.name != null &&
        helper.matches(<String?>[
          attribute.settingNote,
          attribute.settingName,
          attribute.id,
          attribute.name,
        ])) {
      result.add(
        helper.getPreferenceTile(
          title: attribute.name!,
          context: context,
          onTapCallback: () async {
            // checks each attribute inside the group and opens attribute group that holds the search match, e.g. allergens for query "gluten"
            await userPreferences.setActiveAttributeGroup(group.id!);
          },
          icon: getAttributeDisplayIcon(
            attribute,
            context: context,
            isFoodPreferences: true,
            foregroundColor: Colors.white,
            backgroundColor: backgroundColor,
            size: 20.0,
          ),
        ),
      );
    }
  }
  return result;
}