-
Notifications
You must be signed in to change notification settings - Fork 486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add second animation curve option for modal bottom sheet #417
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -36,6 +36,7 @@ class ModalBottomSheet extends StatefulWidget { | |||||||||||||||||||
super.key, | ||||||||||||||||||||
required this.animationController, | ||||||||||||||||||||
this.animationCurve, | ||||||||||||||||||||
this.secondAnimationCurve, | ||||||||||||||||||||
this.enableDrag = true, | ||||||||||||||||||||
this.containerBuilder, | ||||||||||||||||||||
this.bounce = true, | ||||||||||||||||||||
|
@@ -68,6 +69,7 @@ class ModalBottomSheet extends StatefulWidget { | |||||||||||||||||||
/// | ||||||||||||||||||||
/// If no curve is provided it falls back to `decelerateEasing`. | ||||||||||||||||||||
final Curve? animationCurve; | ||||||||||||||||||||
final Curve? secondAnimationCurve; | ||||||||||||||||||||
Comment on lines
70
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also provide documentation what it is used for. |
||||||||||||||||||||
|
||||||||||||||||||||
/// Allows the bottom sheet to go beyond the top bound of the content, | ||||||||||||||||||||
/// but then bounce the content back to the edge of | ||||||||||||||||||||
|
@@ -191,6 +193,7 @@ class ModalBottomSheetState extends State<ModalBottomSheet> | |||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
ParametricCurve<double> animationCurve = Curves.linear; | ||||||||||||||||||||
ParametricCurve<double> secondAnimationCurve = Curves.linear; | ||||||||||||||||||||
|
||||||||||||||||||||
void _handleDragUpdate(double primaryDelta) async { | ||||||||||||||||||||
animationCurve = Curves.linear; | ||||||||||||||||||||
|
@@ -337,10 +340,12 @@ class ModalBottomSheetState extends State<ModalBottomSheet> | |||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
Curve get _defaultCurve => widget.animationCurve ?? _decelerateEasing; | ||||||||||||||||||||
Curve get _defaultSecondCurve => widget.secondAnimationCurve ?? _decelerateEasing; | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Imo should return |
||||||||||||||||||||
|
||||||||||||||||||||
@override | ||||||||||||||||||||
void initState() { | ||||||||||||||||||||
animationCurve = _defaultCurve; | ||||||||||||||||||||
secondAnimationCurve = _defaultSecondCurve; | ||||||||||||||||||||
_bounceDragController = | ||||||||||||||||||||
AnimationController(vsync: this, duration: Duration(milliseconds: 300)); | ||||||||||||||||||||
|
||||||||||||||||||||
|
@@ -368,7 +373,7 @@ class ModalBottomSheetState extends State<ModalBottomSheet> | |||||||||||||||||||
animation: widget.animationController, | ||||||||||||||||||||
builder: (context, Widget? child) { | ||||||||||||||||||||
assert(child != null); | ||||||||||||||||||||
final animationValue = animationCurve.transform( | ||||||||||||||||||||
final animationValue = (_dismissUnderway && !isDragging ? secondAnimationCurve : animationCurve).transform( | ||||||||||||||||||||
widget.animationController.value, | ||||||||||||||||||||
); | ||||||||||||||||||||
Comment on lines
+376
to
378
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
|
||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend naming it
reverseAnimationCurve