MBDropdownElement constructor

MBDropdownElement({
  1. required Map<String, dynamic> dictionary,
})

Initializes a dropdown element with the dictionary returned by the MBurger APIs.

  • Parameters:
    • dictionary: The dictionary returned by the APIs.

Implementation

factory MBDropdownElement({required Map<String, dynamic> dictionary}) {
  String? selectedOption;
  List<MBDropdownElementOption> options = [];

  if (dictionary['value'] is String) {
    selectedOption = dictionary['value'] as String;
  }

  if (dictionary['options'] is List) {
    List<Map<String, dynamic>> optionsMaps =
        List<Map<String, dynamic>>.from(dictionary['options'] as List);
    options = optionsMaps
        .map((o) => MBDropdownElementOption.fromDictionary(dictionary: o))
        .toList();
  }

  return MBDropdownElement._(
    dictionary: dictionary,
    options: options,
    selectedOption: selectedOption,
  );
}