• Simon Friis Vindum's avatar
    Fix initialization of time in repeat on AnimationController (#142887) · 6c78e36c
    Simon Friis Vindum authored
    This PR fixes #142885.
    
    The issue is that in `_RepeatingSimulation` the initial time is calculated as follows:
    
    ```
    (initialValue / (max - min)) * (period.inMicroseconds / Duration.microsecondsPerSecond)
    ```
    
    This calculation does not work in general. For instance, if `max` is 300, `min` is 100, and `initialValue` is 100 then `initialValue / (max - min)` is 1/2 when it should be 0
    
    The current tests work by happenstance because the numbers used happen to work. To reveal the bug I've added some more tests similar to the existing ones but with different numbers.
    
    A "side-effect" of the incorrect calculation is that if `initialValue` is 0, then the animation will always start from `min` no matter what. For instance, in one of the tests, an `AnimationController` with the value 0 is told to `repeat` between 0.5 and 1.0, and this starts the animation from 0.5. To preserve this behavior, and to more generally handle the case where the initial value is out of bounds, this PR clamps the initial value to be within the lower and upper bounds of the repetition.
    
    Just for reference, this calculation was introduced at https://github.com/flutter/flutter/pull/25125.
    6c78e36c
Name
Last commit
Last update
..
flutter Loading commit data...
flutter_driver Loading commit data...
flutter_goldens Loading commit data...
flutter_localizations Loading commit data...
flutter_test Loading commit data...
flutter_tools Loading commit data...
flutter_web_plugins Loading commit data...
fuchsia_remote_debug_protocol Loading commit data...
integration_test Loading commit data...
analysis_options.yaml Loading commit data...