getState<T> method
Gets the state associated with the specified offset.
extent: The current extent of the sheet.offset: The offset value to evaluate.- Returns: The state index corresponding to the offset.
Implementation
int getState<T>(
{required MultiStateSheetExtent<T> extent, required double offset}) =>
cachedState.putIfAbsent(extent.offset, offset, () {
final (firstOffset, lastOffset) = getClosestOffsets(offset, extent);
if ((offset - lastOffset).abs() >= (offset - firstOffset).abs()) {
return getStateFromOffset(firstOffset, extent);
}
return getStateFromOffset(lastOffset, extent);
});