findNode method

Node<T>? findNode(
  1. Key key
)

Loads this controller with data from a JSON String This method expects the user to properly update the state

setState(() {
  TreeViewController.loadFromJson(json: jsonString);
});

Search the node that has a key value equal to the specified key.

Implementation

// static TreeViewController<T> loadFromJson<T>({String json = '{}'}) {
//   // final jsonList = jsonDecode(json) as List<dynamic>;
//   // final List<Map<String, dynamic>> list =
//   //     List<Map<String, dynamic>>.from(jsonList);
//   // return loadFromMap<T>(list: list);
//   return TreeViewController();
// }

// /// Loads this controller with data from a Map.
// /// This method expects the user to properly update the state
// ///
// /// ```dart
// /// setState(() {
// ///   controller = controller.loadFromMap(list: dataMap);
// /// });
// /// ```
// static TreeViewController<T> loadFromMap<T>(
//     {List<Map<String, dynamic>> list = const []}) {
//   final List<Node<T>> treeData = list
//       .map((Map<String, dynamic> item) => Node.fromJson(item) as Node<T>)
//       .toList();
//   return TreeViewController<T>(nodes: treeData);
// }

/// Search the node that has a key value equal to the specified key.
Node<T>? findNode(Key key) {
  final iter = _root.descendants.iterator;
  Node<T>? found;
  while (iter.moveNext()) {
    if (iter.current.key == key) {
      found = iter.current;
      break;
    }
  }
  return found;
}