fetchAttributeGroups method

Future<List<AttributeGroup>?> fetchAttributeGroups()

Implementation

Future<List<AttributeGroup>?> fetchAttributeGroups() async {
  try {
    final String languageCode = ProductQuery.getLanguage().code;
    final Uri uri = AvailableAttributeGroups.getUri(
      languageCode,
      uriHelper: getUriProductHelper(),
    );

    // TODO(monsieurtanuki): cache it?
    final http.Response response = await http.get(uri);
    if (response.statusCode != 200) {
      return null;
    }

    final AvailableAttributeGroups availableAttributeGroups =
        AvailableAttributeGroups.loadFromJSONString(response.body);
    return availableAttributeGroups.attributeGroups;
  } catch (e) {
    debugPrint('Error fetching attribute groups for $name: $e');
    return null;
  }
}