Last active
November 15, 2023 01:38
-
-
Save luo3house/124f1a2902f5d9d3c681053f2c95d8f5 to your computer and use it in GitHub Desktop.
snap value by min, max, step
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/foundation.dart'; | |
// V0.85, S0.1 -> 0.9 | |
// V0.84, S0.1 -> 0.8 | |
// V0.48, S1.0 -> 0 | |
// V4.80, S5.0 -> 5 | |
// V6.10, S3.0 -> 6 | |
double snapValue(double value, double min, double max, double step) { | |
final wideValue = () { | |
if (step == 0) return value; // no restricted | |
return ((value / step).round() * step); | |
}(); | |
return clampDouble(wideValue, min, max); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment