update method

  1. @override
(TreeModel<T>, Cmd?) update(
  1. Msg msg
)
override

Updates the component state in response to a message.

Returns the updated component (often this) and an optional command.

Implementation

@override
(TreeModel<T>, Cmd?) update(Msg msg) {
  switch (msg) {
    case KeyMsg(:final key):
      if (keyMatches(key, [keyMap.up])) {
        moveBy(-1);
      } else if (keyMatches(key, [keyMap.down])) {
        moveBy(1);
      } else if (keyMatches(key, [keyMap.home])) {
        _moveToBoundary(first: true);
      } else if (keyMatches(key, [keyMap.end])) {
        _moveToBoundary(first: false);
      } else if (keyMatches(key, [keyMap.pageUp])) {
        moveBy(-(height > 0 ? height : 1));
      } else if (keyMatches(key, [keyMap.pageDown])) {
        moveBy(height > 0 ? height : 1);
      } else if (keyMatches(key, [keyMap.panLeft])) {
        panBy(-2);
      } else if (keyMatches(key, [keyMap.panRight])) {
        panBy(2);
      } else if (keyMatches(key, [keyMap.left])) {
        _collapseOrSelectParent();
      } else if (keyMatches(key, [keyMap.right])) {
        _expandOrSelectChild();
      } else if (keyMatches(key, [keyMap.toggle])) {
        final selected = selectedItem;
        if (selected != null) toggle(selected.id);
      } else if (keyMatches(key, [keyMap.activate])) {
        final selected = selectedItem;
        if (selected != null) {
          return (this, Cmd.message(TreeItemActivatedMsg<T>(selected)));
        }
      }
    case MouseMsg(:final action, :final button)
        when action == MouseAction.wheel ||
            button == MouseButton.wheelUp ||
            button == MouseButton.wheelDown:
      if (button == MouseButton.wheelUp) {
        scrollBy(-mouseWheelDelta);
      } else {
        scrollBy(mouseWheelDelta);
      }
    default:
      break;
  }
  return (this, null);
}