frictionFromScaleState function

double frictionFromScaleState({
  1. required ScaleAxisState state,
  2. required ShrinkBounds? shrink,
  3. required ExpandBounds? expand,
  4. required double delta,
})

Friction-scaled width delta given a scale-axis state. Absent side config = blocked (returns 0). Absent friction = free (returns delta).

Implementation

double frictionFromScaleState({
  required ScaleAxisState state,
  required ShrinkBounds? shrink,
  required ExpandBounds? expand,
  required double delta,
}) {
  if (delta == 0) return 0;
  final sideConfig = switch (state.activeSide) {
    .shrink => shrink as Bounds?,
    .expand => expand as Bounds?,
  };
  if (sideConfig == null) return 0;
  final fc = sideConfig.friction;
  if (fc == null) return delta;
  final friction = state.pastDisplay
      ? (state.extending ? fc.extendingPastDisplay : fc.retractingPastDisplay)
      : (state.extending ? fc.extending : fc.retracting);
  if (friction == null) return delta;
  return delta * (1.0 - friction.evaluate(state.progress));
}