percentPosition method

double percentPosition(
  1. double min,
  2. double max
)

Get Panel's current position as percentage between 0.0 and 1.0, given minimum and maximum positions.

This can be used, for example, to get values for an AnimationController.

e.g.,

PanelSize.closedHeight = 0.25

PanelSize.collapsedHeight = 0.40

PanelSize.expandedHeight = 0.75

If current state is PanelState.collapsed, (position would be 0.4), and you pass min as PanelSize.closedHeight and max as PanelSize.expandedHeight, this will return '0.3'.

If current position is 0.6, this will return '0.7'.

Implementation

double percentPosition(double min, double max) {
  if (min >= max) return 0.0;

  if (currentPosition < min) return 0.0;

  if (currentPosition > max) return 1.0;

  double percent = ((currentPosition - min) / (max - min));

  return (double.parse(percent.toStringAsFixed(5)));
}