changeState method

Future<bool> changeState(
  1. bool expand,
  2. bool byUserAction,
  3. StreamController stream
)

Changes the state of the panel either to expanded or not. Returns a Future

Implementation

Future<bool> changeState(
    bool expand, bool byUserAction, StreamController stream) {
  if (isExpanded == expand) {
    return Future.value(true);
  }
  var actionCtrl = AsyncActionController<bool>();
  stream.add(actionCtrl.action);
  var stateWasInitialized = initialized;
  actionCtrl.execute(() {
    // Update our state before redrawing. State changes need to occur before
    // follow ups (animation or autofocus) so that styles and deferred content
    // can update.
    _isExpanded.value = expand;
    if (expand) _contentVisible.add(true);
    if (byUserAction) _isExpandedChangeByUserAction.add(expand);
    _changeDetector.markForCheck();
    if (expand) {
      _domService.scheduleWrite(() {
        if (autoFocusChild != null) {
          autoFocusChild!.focus();
        } else if (byUserAction && _focusOnOpenChild != null) {
          _focusOnOpenChild?.focus();
        }
      });
    }
    if (stateWasInitialized) _transitionHeightChange(expand);
    return true;
  }, valueOnCancel: false);
  return actionCtrl.action!.onDone;
}