toggleComponent method

void toggleComponent(
  1. LayoutPosition position, {
  2. bool? forceState,
})

切换指定位置组件的展开状态 position 组件位置 forceState 强制设置状态,null表示切换当前状态

Implementation

void toggleComponent(LayoutPosition position, {bool? forceState}) {
  if (!isBound) {
    debugPrint('ClassLayoutController: Controller not bound to layout');
    return;
  }

  final currentState = isExpanded(position);
  final targetState = forceState ?? !currentState;

  // 如果目标状态与当前状态相同,则不执行操作
  if (targetState == currentState) {
    return;
  }

  _state!.toggleComponent(position);
  notifyListeners();
}