updateComponents method

double? updateComponents(
  1. double topHeaderHeight,
  2. double headerHeight,
  3. double contentHeight,
  4. double footerHeight,
)

Method to update size of the sheet's components.

Implementation

double? updateComponents(
  double topHeaderHeight,
  double headerHeight,
  double contentHeight,
  double footerHeight,
) {
  if (componentSizes.topHeader != topHeaderHeight ||
      componentSizes.header != headerHeight ||
      componentSizes.content != contentHeight ||
      componentSizes.footer != footerHeight) {
    final needsResetupClipping = behavior.clipByHeader &&
        behavior.headerShiftHeight != headerHeight &&
        _state == 0 &&
        _interpolation == 0.0;

    componentSizes = SheetWidgetSizes(
      topHeader: topHeaderHeight,
      header: headerHeight,
      content: contentHeight,
      footer: footerHeight,
    );

    /// Reset up behavior if the components are changed their sizes in the initial state
    ///
    /// This is needed to recalculate the snapping positions based on the new component sizes.
    ///
    /// It's could happen then components are changed their sizes on their own without the sheet height update.
    /// For example, then the component was waiting for the data to be loaded and change it's size then the data is loaded.
    final isComponentsUpdatedAtTheInitialState =
        anchoredState == initialState &&
            stateInterpolation == 0 &&
            initialComponentSizes != componentSizes;
    if (initialComponentSizes.isZero ||
        isComponentsUpdatedAtTheInitialState) {
      initialComponentSizes = componentSizes;
      behavior.setup(this);
      _offset = behavior.statePosition(extent: this, state: initialState);
      updateState();
      _doNotMarkNeedsLayout = true;
      Future(() => onOffsetChanged?.call());
      return _offset;
    } else if (needsResetupClipping) {
      behavior.setup(this);

      _offset = behavior
          .statePosition(extent: this, state: _state)
          .clamp(minOffset, maxOffset);
      updateState();
      _doNotMarkNeedsLayout = true;
      Future(() => onOffsetChanged?.call());
      return _offset;
    }
  }
  return null;
}