fromMap<T> static method

Node<T> fromMap<T>(
  1. Map<String, dynamic> map
)

Creates a Node from a Map<String, dynamic> map. The map should contain a "label" value. If the key value is missing, it generates a unique key. If the expanded value, if present, can be any 'truthful' value. Excepted values include: 1, yes, true and their associated string values.

Implementation

static Node<T> fromMap<T>(Map<String, dynamic> map) {
  String? _key = map['key'];
  String _label = map['label'];
  var _data = map['data'];
  List<Node> _children = [];
  if (_key == null) {
    _key = Utilities.generateRandom();
  }
  // if (map['icon'] != null) {
  // int _iconData = int.parse(map['icon']);
  // if (map['icon'].runtimeType == String) {
  //   _iconData = int.parse(map['icon']);
  // } else if (map['icon'].runtimeType == double) {
  //   _iconData = (map['icon'] as double).toInt();
  // } else {
  //   _iconData = map['icon'];
  // }
  // _icon = const IconData(_iconData);
  // }
  if (map['children'] != null) {
    List<Map<String, dynamic>> _childrenMap = List.from(map['children']);
    _children = _childrenMap
        .map((Map<String, dynamic> child) => Node.fromMap(child))
        .toList();
  }
  return Node<T>(
    key: '$_key',
    label: _label,
    data: _data,
    expanded: Utilities.truthful(map['expanded']),
    parent: Utilities.truthful(map['parent']),
    children: _children,
  );
}