MBShopifyCollectionElement constructor
Initializes a collection element with the dictionary returned by the MBurger APIs.
- Parameters:
dictionary
: Thedictionary
returned by the APIs.
Implementation
factory MBShopifyCollectionElement(
{required Map<String, dynamic> dictionary}) {
List<MBShopifyCollection> collections = [];
dynamic valueFromDictionary = dictionary['value'];
List<Map<String, dynamic>>? value;
if (valueFromDictionary is String) {
if (valueFromDictionary != '') {
List<dynamic> valueList =
json.decode(valueFromDictionary) as List<dynamic>;
value = List<Map<String, dynamic>>.from(valueList);
}
} else if (valueFromDictionary is List) {
value = List<Map<String, dynamic>>.from(valueFromDictionary);
}
if (value != null) {
collections =
value.map((img) => MBShopifyCollection(dictionary: img)).toList();
}
return MBShopifyCollectionElement._(
dictionary: dictionary,
collections: collections,
);
}