MBBlock.fromDictionary constructor

MBBlock.fromDictionary(
  1. Map<String, dynamic> dictionary
)

Initializes a block with the dictionary returned by the MBurger APIs.

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

Implementation

factory MBBlock.fromDictionary(Map<String, dynamic> dictionary) {
  int id = dictionary['id'] is int ? dictionary['id'] as int : 0;
  String title =
      dictionary['title'] is String ? dictionary['title'] as String : '';
  String subtitle = dictionary['subtitle'] is String
      ? dictionary['subtitle'] as String
      : '';
  int order = dictionary['order'] as int;

  List<MBSection> sections = [];
  if (dictionary['sections'] != null) {
    List<Map<String, dynamic>> sectionsDictionaries =
        List.castFrom<dynamic, Map<String, dynamic>>(
            dictionary['sections'] as List);
    sections =
        sectionsDictionaries.map((e) => MBSection.fromDictionary(e)).toList();
  }

  return MBBlock(
    id: id,
    title: title,
    subtitle: subtitle,
    order: order,
    sections: sections,
  );
}