41 Commits

Author SHA1 Message Date
Tong Mu
cc35800e6a
Fix SpringSimulation formula for underdamping (#165017)
Fix https://github.com/flutter/flutter/issues/163858

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-03-21 20:46:07 +00:00
Bernardo Ferrari
b35c6be8c9
Add withDurationAndBounce to SpringDescription (#164411)
Part of https://github.com/flutter/flutter/issues/152587

###  Description:
With `withDurationAndBounce` (we could also rename to `withDuration`),
the user only has to worry about a single attribute: the bounce (and
duration, but they would have to worry with duration anyway. If they
don't, there is a default value already). The standard
`SpringDescription` has 3 values, so it is way more abstract. This
should help a lot people to make beautiful spring animations using
Flutter.

<img width="838" alt="image"
src="https://github.com/user-attachments/assets/4d0dccc7-0f97-4a13-99a4-268228b87f08"
/>

### Negative bounce:

I didn't enable bounce to be negative because the behavior is super
tricky. I don't know what formula Apple is using, but seems like it is
not public. There are many different formulas we can use, including the
one provided on the original issue, but then there is the risk of people
complaining it works differently than SwiftUI. I need to check if other
projects (react-spring, framer motion) support negative bounce, but
feels like this is something 99.9999% of people wouldn't expect or use,
so I think we are safe. I couldn't find a single usage of negative
bounce on Swift in all GitHub (without a duration, using code-search, vs
5k cases with positive values). Not even sure the todo is needed, but
won't hurt.


### Comparison

<details>
  <summary>Dart vs Swift testing results</summary>

```dart
 testWidgets('Spring Simulation Tests - Matching SwiftUI', (WidgetTester tester) async {
      // Test cases matching the Swift code's ranges
      List<({Duration duration, double bounce})> testCases = [
        (duration: const Duration(milliseconds: 100), bounce: 0.0),
        (duration: const Duration(milliseconds: 100), bounce: 0.3),
        (duration: const Duration(milliseconds: 100), bounce: 0.8),
        (duration: const Duration(milliseconds: 100), bounce: 1.0),
        (duration: const Duration(milliseconds: 500), bounce: 0.0),
        (duration: const Duration(milliseconds: 500), bounce: 0.3),
        (duration: const Duration(milliseconds: 500), bounce: 0.8),
        (duration: const Duration(milliseconds: 500), bounce: 1.0),
        (duration: const Duration(milliseconds: 1000), bounce: 0.0),
        (duration: const Duration(milliseconds: 1000), bounce: 0.3),
        (duration: const Duration(milliseconds: 1000), bounce: 0.8),
        (duration: const Duration(milliseconds: 1000), bounce: 1.0),
        (duration: const Duration(milliseconds: 2000), bounce: 0.0),
        (duration: const Duration(milliseconds: 2000), bounce: 0.3),
        (duration: const Duration(milliseconds: 2000), bounce: 0.8),
        (duration: const Duration(milliseconds: 2000), bounce: 1.0),
      ];

      for (final testCase in testCases) {
        SpringDescription springDesc = SpringDescription.withDurationAndBounce(
          duration: testCase.duration,
          bounce: testCase.bounce,
        );

        print(
          'Duration: ${testCase.duration.inMilliseconds / 1000}, Bounce: ${testCase.bounce}, Mass: ${springDesc.mass}, Stiffness: ${springDesc.stiffness}, Damping: ${springDesc.damping}',
        );
      }
    });
```
Output:
```
Duration: 0.1, Bounce: 0.0, Mass: 1.0, Stiffness: 3947.8417604357423, Damping: 125.66370614359171
Duration: 0.1, Bounce: 0.3, Mass: 1.0, Stiffness: 3947.8417604357423, Damping: 87.9645943005142
Duration: 0.1, Bounce: 0.8, Mass: 1.0, Stiffness: 3947.8417604357423, Damping: 25.132741228718338
Duration: 0.1, Bounce: 1.0, Mass: 1.0, Stiffness: 3947.8417604357423, Damping: 0.0
Duration: 0.5, Bounce: 0.0, Mass: 1.0, Stiffness: 157.91367041742973, Damping: 25.132741228718345
Duration: 0.5, Bounce: 0.3, Mass: 1.0, Stiffness: 157.91367041742973, Damping: 17.59291886010284
Duration: 0.5, Bounce: 0.8, Mass: 1.0, Stiffness: 157.91367041742973, Damping: 5.026548245743668
Duration: 0.5, Bounce: 1.0, Mass: 1.0, Stiffness: 157.91367041742973, Damping: 0.0
Duration: 1.0, Bounce: 0.0, Mass: 1.0, Stiffness: 39.47841760435743, Damping: 12.566370614359172
Duration: 1.0, Bounce: 0.3, Mass: 1.0, Stiffness: 39.47841760435743, Damping: 8.79645943005142
Duration: 1.0, Bounce: 0.8, Mass: 1.0, Stiffness: 39.47841760435743, Damping: 2.513274122871834
Duration: 1.0, Bounce: 1.0, Mass: 1.0, Stiffness: 39.47841760435743, Damping: 0.0
Duration: 2.0, Bounce: 0.0, Mass: 1.0, Stiffness: 9.869604401089358, Damping: 6.283185307179586
Duration: 2.0, Bounce: 0.3, Mass: 1.0, Stiffness: 9.869604401089358, Damping: 4.39822971502571
Duration: 2.0, Bounce: 0.8, Mass: 1.0, Stiffness: 9.869604401089358, Damping: 1.256637061435917
Duration: 2.0, Bounce: 1.0, Mass: 1.0, Stiffness: 9.869604401089358, Damping: 0.0
```

Swift:
```swift
import SwiftUI
import XCTest

class SpringParameterTests: XCTestCase {

    func printSpringParameters(duration: Double, bounce: Double) {
        let spring = Spring(duration: duration, bounce: bounce) // Let SwiftUI do its thing
        print("Duration: \(duration), Bounce: \(bounce), Mass: \(spring.mass), Stiffness: \(spring.stiffness), Damping: \(spring.damping)")
    }

    func testParameterExtraction() {
        // Test a range of durations and bounces
        let durations: [Double] = [0.1, 0.5, 1.0, 2.0]
        let bounces: [Double] = [0.0, 0.3, 0.8, 1.0]

        for duration in durations {
            for bounce in bounces {
                printSpringParameters(duration: duration, bounce: bounce)
            }
        }
    }
}
```
Output:
```
Duration: 0.1, Bounce: 0.0, Mass: 1.0, Stiffness: 3947.8417604357433, Damping: 125.66370614359172
Duration: 0.1, Bounce: 0.3, Mass: 1.0, Stiffness: 3947.841760435743, Damping: 87.96459430051421
Duration: 0.1, Bounce: 0.8, Mass: 1.0, Stiffness: 3947.8417604357423, Damping: 25.132741228718338
Duration: 0.1, Bounce: 1.0, Mass: 1.0, Stiffness: 3947.8417604357433, Damping: 0.0
Duration: 0.5, Bounce: 0.0, Mass: 1.0, Stiffness: 157.91367041742973, Damping: 25.132741228718345
Duration: 0.5, Bounce: 0.3, Mass: 1.0, Stiffness: 157.9136704174297, Damping: 17.59291886010284
Duration: 0.5, Bounce: 0.8, Mass: 1.0, Stiffness: 157.9136704174297, Damping: 5.026548245743668
Duration: 0.5, Bounce: 1.0, Mass: 1.0, Stiffness: 157.91367041742973, Damping: 0.0
Duration: 1.0, Bounce: 0.0, Mass: 1.0, Stiffness: 39.47841760435743, Damping: 12.566370614359172
Duration: 1.0, Bounce: 0.3, Mass: 1.0, Stiffness: 39.478417604357425, Damping: 8.79645943005142
Duration: 1.0, Bounce: 0.8, Mass: 1.0, Stiffness: 39.478417604357425, Damping: 2.513274122871834
Duration: 1.0, Bounce: 1.0, Mass: 1.0, Stiffness: 39.47841760435743, Damping: 0.0
Duration: 2.0, Bounce: 0.0, Mass: 1.0, Stiffness: 9.869604401089358, Damping: 6.283185307179586
Duration: 2.0, Bounce: 0.3, Mass: 1.0, Stiffness: 9.869604401089356, Damping: 4.39822971502571
Duration: 2.0, Bounce: 0.8, Mass: 1.0, Stiffness: 9.869604401089356, Damping: 1.256637061435917
Duration: 2.0, Bounce: 1.0, Mass: 1.0, Stiffness: 9.869604401089358, Damping: 0.0
```
There are minor differences which should be rounding errors.

</details>
2025-03-11 07:44:29 +00:00
Michael Goderbauer
5491c8c146
Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
2024-12-19 20:06:21 +00:00
Tong Mu
c16aa2d232
Make animation and router support simulation, and use Spring for Cupertino (#155575)
This PR makes `TransitionRoute` support driving the animation with
`Simulation`. This is needed for Cupertino widgets, since iOS use
"spring simulations" for a majority of their animations.

This PR also applies the standard spring animation to
`CupertinoDialogRoute` (alert dialogs) and `CupertinoModalPopupRoute`
(action sheets). (This PR does not yet support customizing the spring
parameters or conveniently using the springs for custom routes, which
are left for future PRs.)

### Comparison

I tried to create a comparison video for action sheets, however the
difference is far less noticeable than I expected. (All clips are
precisely aligned at the moment the pointer is lifted.) I guess the
original curve _is_ good enough. Nevertheless, the spring simulation is
the correct one and we should support it.

Edit: [The
comment](https://github.com/flutter/flutter/pull/155575#issuecomment-2489303282)
below also mentioned that supporting spring animation will improve the
fidelity when the animation is caused by a user gesture. I assume this
requires initial speed, which is not supported by this PR but we can add
it in the future.


https://github.com/user-attachments/assets/06d2f684-ad1c-4a4d-8663-a561895f45e9

Also, Flutter's response seems to be always a moment slower than
SwiftUI, possibly because Flutter requiring two frames to start the
animation (one frame to add the transition widget, one frame for the
animation to actually progress.) We probably want to solve it in the
future.

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2024-12-12 21:56:11 +00:00
Greg Price
a28aae918e
Remove no-shuffle from framework tests, part 1: easy cases (#123751)
Remove no-shuffle from framework tests, part 1: easy cases
2023-03-30 18:28:51 +00:00
Greg Price
97938859e0
Fix buggy formula for critically-damped springs (#120488)
Fixes #109675.

This formula would produce an initial velocity quite different
from the one specified as an argument.

To update the test, I computed the expected results separately
by using the physical formula.

Happily, the framework by default never ends up actually exercising
this code.  Of the four SpringDescription call sites within the
framework, two are explicitly overdamped; the other two are by
design critically damped, but due to rounding they end up being
treated as (very slightly) overdamped too.  Details here:
  https://github.com/flutter/flutter/issues/109675#issuecomment-1423674855

So the only way an app could be affected by this bug is if it called
a SpringDescription constructor itself, and managed to create a spring
description where the distinguishing formula in _SpringSolution comes
out exactly equal to zero.  It's likely nobody has ever shipped such
an app, because the behavior this produces would be so wildly wrong
that it'd be hard to miss when exercised.

Co-authored-by: Kate Lovett <katelovett@google.com>
2023-02-23 19:29:32 +00:00
Ahmed Ashour
1fd71de0c5
Remove superfluous words from comments (#119055)
* Remove superfluous words from comments.

* Revert `win32_window.h`

Which seems to come from `gallery`
2023-01-25 20:23:24 +00:00
Michael Goderbauer
b308555ed1
Enable dangling_library_doc_comments and library_annotations lints (#117365) 2022-12-20 16:03:21 -08:00
Callum Moffat
70b19ff987
Add macOS-specific scroll physics (#108298) 2022-09-19 20:08:03 +00:00
Ian Hickson
61a0add286
Enable avoid_redundant_argument_values lint (#91409) (#91462) 2021-10-08 09:25:14 -07:00
Zachary Anderson
b9d2177da0
Revert "Enable avoid_redundant_argument_values lint (#91409)" (#91461)
This reverts commit 5fd259be244244e14ff87fee9b6a721625f952cd.
2021-10-07 21:11:07 -07:00
Ian Hickson
5fd259be24
Enable avoid_redundant_argument_values lint (#91409) 2021-10-07 20:13:02 -07:00
Greg Spencer
738ce43d97
Randomize tests, exclude tests that fail with randomization. (#86793)
* Randomize tests, exclude tests that fail with randomization.

* Disable some more tool tests
2021-07-26 23:40:49 -07:00
Greg Spencer
6adea05276
Revert "Randomize Framework tests, opt out some tests that currently fail. (#85159)" (#85673)
This reverts commit b5f9612 because it is taking about 40% longer to run the tests, which is causing timeouts.
2021-06-30 19:38:09 -07:00
Greg Spencer
b5f9612cac
Randomize Framework tests, opt out some tests that currently fail. (#85159)
This turns on order shuffling for all tests that don't fail with it on, marking those tests that do fail with a tag so that they will be run without shuffling on.

To determine which tests fail with it on, I ran all the tests 100 times with different random shuffle seeds, and then also ran it with the date seeds from today until the end of July, and tagged all of the test suites (files) that fail, with a seed that caused them to fail.
2021-06-29 13:46:13 -07:00
Ian Hickson
4bb504652d
More toStrings and tests for physics (#82503) 2021-05-20 00:09:02 -07:00
Alexandre Ardhuin
d36d5ae35d
add missing trailing commas (#80995) 2021-04-22 19:39:02 -07:00
Ian Hickson
f3c25fa07a
Align more closely with package:test (#77118) (#78343) 2021-03-16 13:58:02 -07:00
Zachary Anderson
e7e1a04aa3
Revert "Align more closely with package:test (#77118)" (#78329)
This reverts commit 0cbe597540f6b51ab7157ab8747906e9923b79e4.
2021-03-16 09:26:34 -07:00
Ian Hickson
0cbe597540
Align more closely with package:test (#77118) 2021-03-15 16:28:02 -07:00
Chris Bracken
c0ea00ed3f
Prefer moreOrLessEquals over closeTo (#64915)
Flutter's `moreOrLessEquals` has a few advantages over `closeTo` from
the `matcher` package:

   * It emits the epsilon value in the test result on failure.
   * It uses a named parameter for epsilon, which improves readability
     at the call site.
   * It has a reasonable default for epsilon in cases where something
     more specific isn't required.

Using it also has the nice property that it aids in its own discovery
when when people go looking for such functionality in new tests.

This change also includes a couple unrelated whitespace formatting cleanups.
2020-08-30 22:20:16 -07:00
Ian Hickson
4fcc2617d5
Migrate physics tests to NNBD (#64584) 2020-08-26 00:46:03 -07:00
Gary Qian
73560d4bff
Docs 'that that' fix (#50237) 2020-06-16 09:20:07 -07:00
Alexandre Ardhuin
4d7525f05c
Opt out nnbd in packages/flutter (#59186)
* add language version 2.8 in packages/flutter

* enable non-nullable analyzer flag
2020-06-11 14:11:30 +02:00
Ian Hickson
449f4a6673
License update (#45373)
* Update project.pbxproj files to say Flutter rather than Chromium

Also, the templates now have an empty organization so that we don't cause people to give their apps a Flutter copyright.

* Update the copyright notice checker to require a standard notice on all files

* Update copyrights on Dart files. (This was a mechanical commit.)

* Fix weird license headers on Dart files that deviate from our conventions; relicense Shrine.

Some were already marked "The Flutter Authors", not clear why. Their
dates have been normalized. Some were missing the blank line after the
license. Some were randomly different in trivial ways for no apparent
reason (e.g. missing the trailing period).

* Clean up the copyrights in non-Dart files. (Manual edits.)

Also, make sure templates don't have copyrights.

* Fix some more ORGANIZATIONNAMEs
2019-11-27 15:04:02 -08:00
Jonah Williams
05e92c828b
Compatibility pass on flutter/physics tests for JavaScript compilation. (6) (#33359) 2019-06-11 09:09:13 -07:00
Alexandre Ardhuin
d927c93310
Unnecessary new (#20138)
* enable lint unnecessary_new

* fix tests

* fix tests

* fix tests
2018-09-12 08:29:29 +02:00
Ian Hickson
686d8f8a22 Shim package:test to avoid matcher issues (#20602)
* Upgrade everything except matcher.
* Roll matcher (and test)
* Adjust tests that depend on flutter:test directly to depend on a shim
* Require use of package:test shim and remove other references to package:test
2018-08-14 20:33:58 -07:00
Jason Simmons
466d15433f
Use Dart 2 camel case constants (#15360) 2018-03-12 11:06:32 -07:00
Michael Goderbauer
72517f0a0a
Encode scrolling status into tree (#14536) 2018-02-09 18:33:50 -08:00
Alexandre Ardhuin
841d5d7bd5
prefer_const_declarations on local variables (#14358) 2018-02-01 07:51:26 +01:00
Jeff McGlynn
473d75a6e3 PageView ballistics overshoot the page on some devices (#12884)
* PageView ballistics overshoot the page on some devices

On some devices, such as Cupertino “Plus”-sized devices, scrolling left on the first page of a PageView will overshoot the first page and land on the second page.

The issue is that applyContentDimensions incorrectly detects a content size change due to a floating point comparison on certain screen sizes (18257.400000000005 vs 18257.4)

To fix this, perform a nearEqual comparison in applyContentDimensions.

* Apply style changes to nearEqual for code review feedback.
2017-11-14 14:34:43 -08:00
Brenton Simpson
58163e0c39 Rename springConstant to stiffness (#11686)
`stiffness` is the name of a spring's `k` input on [iOS](https://developer.apple.com/documentation/quartzcore/caspringanimation), [Android](https://developer.android.com/topic/libraries/support-library/preview/spring-animation.html), and the [Web](bbc0f831e2/src/index.js (L11-L22)).  To ensure the API is familiar to and easily understood by developers coming from other platforms, Flutter should follow this convention as well.

This is a minimally-breaking change.  Across [all of GitHub](https://github.com/search?l=Dart&q=springConstant&type=Code&utf8=%E2%9C%93), there are only 2 uses of the `springConstant` API (in Mondrian).  Those can be easily changed to use this name.

Closes #11684
2017-08-23 12:58:33 -07:00
Hans Muller
4ca447b61e Refactored the iOS Scrolling Simulation (#9754) 2017-05-03 15:54:17 -07:00
Chris Bracken
46291903e0 Declare locals final where not reassigned (tests) (#8566) 2017-03-03 17:43:22 -08:00
Adam Barth
90574b0478 Remove Scrollable1 (#8225)
All the clients have migrated to Scrollable2.
2017-02-16 16:41:24 -08:00
Adam Barth
2b742289d4 Fix several minor bugs and add many tests (#7506)
* MultiTapGestureRecognizer previously would assert if there was no
   competition.
 * GestureArenaTeam would always select the first recongizer as the
   winner even if a later recognizer actually accepted the pointer
   sequence.
 * debugPrintStack would fail a type check if maxFrames was non-null.
 * FractionalOffset.lerp would throw a null-pointer exception if its
   second argument was null.

Also, add a number of tests for previously untested lines of code.
2017-01-17 11:00:10 -08:00
Ian Hickson
79c8e5c7c7 Add a toString to Simulation (#7364)
Also, make hasOneLineDescription more discerning.
Also, add a test for hasOneLineDescription.
Also, add a test for GravitySimulation, to test the toString.
2017-01-05 16:33:40 -08:00
Alexandre Ardhuin
c8447c91a9 prefer_const_constructor in packages/flutter/test (#7181) 2016-12-09 15:20:27 -08:00
Hans Muller
f167efba49 Tweaked scroll simulation for iOS platform (#6334) 2016-10-14 20:09:19 -07:00
Adam Barth
cbe650a7e6 Move newton into package:flutter (#3585)
Rather that importing `package:newton/newton.dart` you can
`import package:flutter/physics.dart`.

Fixes #2441
2016-04-27 13:09:54 -07:00