Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
4a32e524
Unverified
Commit
4a32e524
authored
Oct 18, 2020
by
nt4f04uNd
Committed by
GitHub
Oct 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SpringDescription parameter for the AnimationController fling method (#65057)
parent
3302a12b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
4 deletions
+42
-4
AUTHORS
AUTHORS
+1
-0
animation_controller.dart
packages/flutter/lib/src/animation/animation_controller.dart
+18
-4
animation_controller_test.dart
...ges/flutter/test/animation/animation_controller_test.dart
+23
-0
No files found.
AUTHORS
View file @
4a32e524
...
...
@@ -68,3 +68,4 @@ meritozh <ah841814092@gmail.com>
Terrence Addison Tandijono(flotilla) <terrenceaddison32@gmail.com>
YeungKC <flutter@yeungkc.com>
Nobuhiro Tabuki <japanese.around30@gmail.com>
nt4f04uNd <nt4f04und@gmail.com>
packages/flutter/lib/src/animation/animation_controller.dart
View file @
4a32e524
...
...
@@ -645,18 +645,27 @@ class AnimationController extends Animation<double>
_checkStatusChanged
();
}
/// Drives the animation with a
critically damped spring (within [lowerBound]
/// and
[upperBound]) and
initial velocity.
/// Drives the animation with a
spring (within [lowerBound] and [upperBound])
/// and initial velocity.
///
/// If velocity is positive, the animation will complete, otherwise it will
/// dismiss.
///
/// The [springDescription] parameter can be used to specify a custom [SpringType.criticallyDamped]
/// or [SpringType.overDamped] spring to drive the animation with. Defaults to null, which uses a
/// [SpringType.criticallyDamped] spring. See [SpringDescription.withDampingRatio] for how
/// to create a suitable [SpringDescription].
///
/// The resulting spring simulation cannot be of type [SpringType.underDamped],
/// as this can lead to unexpected look of the produced animation.
///
/// Returns a [TickerFuture] that completes when the animation is complete.
///
/// The most recently returned [TickerFuture], if any, is marked as having been
/// canceled, meaning the future never completes and its [TickerFuture.orCancel]
/// derivative future completes with a [TickerCanceled] error.
TickerFuture
fling
({
double
velocity
=
1.0
,
AnimationBehavior
?
animationBehavior
})
{
TickerFuture
fling
({
double
velocity
=
1.0
,
SpringDescription
?
springDescription
,
AnimationBehavior
?
animationBehavior
})
{
springDescription
??=
_kFlingSpringDescription
;
_direction
=
velocity
<
0.0
?
_AnimationDirection
.
reverse
:
_AnimationDirection
.
forward
;
final
double
target
=
velocity
<
0.0
?
lowerBound
-
_kFlingTolerance
.
distance
:
upperBound
+
_kFlingTolerance
.
distance
;
...
...
@@ -673,8 +682,13 @@ class AnimationController extends Animation<double>
break
;
}
}
final
S
imulation
simulation
=
SpringSimulation
(
_kFlingS
pringDescription
,
value
,
target
,
velocity
*
scale
)
final
S
pringSimulation
simulation
=
SpringSimulation
(
s
pringDescription
,
value
,
target
,
velocity
*
scale
)
..
tolerance
=
_kFlingTolerance
;
assert
(
simulation
.
type
!=
SpringType
.
underDamped
,
'The resulting spring simulation is of type SpringType.underDamped.
\n
'
'This can lead to unexpected look of the animation, please adjust the springDescription parameter'
);
stop
();
return
_startSimulation
(
simulation
);
}
...
...
packages/flutter/test/animation/animation_controller_test.dart
View file @
4a32e524
...
...
@@ -253,6 +253,29 @@ void main() {
largeRangeController
.
stop
();
});
test
(
'Custom springDescription can be applied'
,
()
{
final
AnimationController
controller
=
AnimationController
(
vsync:
const
TestVSync
(),
);
final
AnimationController
customSpringController
=
AnimationController
(
vsync:
const
TestVSync
(),
);
controller
.
fling
();
// Will produce longer and smoother animation than the default.
customSpringController
.
fling
(
springDescription:
SpringDescription
.
withDampingRatio
(
mass:
0.01
,
stiffness:
10.0
,
ratio:
2.0
,
),
);
tick
(
const
Duration
(
milliseconds:
0
));
tick
(
const
Duration
(
milliseconds:
50
));
expect
(
customSpringController
.
value
<
controller
.
value
,
true
);
});
test
(
'lastElapsedDuration control test'
,
()
{
final
AnimationController
controller
=
AnimationController
(
duration:
const
Duration
(
milliseconds:
100
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment