Skip to content

Commit

Permalink
Add support for a drawer slide animation
Browse files Browse the repository at this point in the history
  • Loading branch information
zbarbuto committed Jan 17, 2025
1 parent 8aa024f commit 00442c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ An advanced drawer widget, that can be fully customized with size, text, color,
|`animateChildDecoration`|Indicates that [childDecoration] might be animated or not.|*bool*|true|
|`rtlOpening`|Opening from Right-to-left.|*bool*|false|
|`disabledGestures`|Disable gestures.|*bool*|false|
|`drawerSlideRatio`|How far the drawer segment should slide with the content.|*double*|0|

## Preview
| Preview Tap | Preview Gesture |
Expand Down
33 changes: 24 additions & 9 deletions lib/src/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AdvancedDrawer extends StatefulWidget {
this.backdrop,
this.openRatio = 0.75,
this.openScale = 0.85,
this.drawerSlideRatio = 0,
this.animationDuration = const Duration(milliseconds: 250),
this.animationCurve,
this.childDecoration,
Expand Down Expand Up @@ -41,6 +42,11 @@ class AdvancedDrawer extends StatefulWidget {
/// Opening ratio.
final double openScale;

/// How far the drawer segment should slide with the content
/// 0 = no slide distance
/// 1 = slide from completely off screen
final double drawerSlideRatio;

/// Animation duration.
final Duration animationDuration;

Expand Down Expand Up @@ -77,6 +83,7 @@ class _AdvancedDrawerState extends State<AdvancedDrawer>
late Animation<double> _drawerScaleAnimation;
late Animation<Offset> _childSlideAnimation;
late Animation<double> _childScaleAnimation;
late Animation<Offset> _drawerSlideAnimation;
late Animation<Decoration> _childDecorationAnimation;

late double _offsetValue;
Expand Down Expand Up @@ -120,15 +127,18 @@ class _AdvancedDrawerState extends State<AdvancedDrawer>
alignment: widget.rtlOpening
? Alignment.centerRight
: Alignment.centerLeft,
child: FractionallySizedBox(
widthFactor: widget.openRatio,
child: ScaleTransition(
scale: _drawerScaleAnimation,
alignment: widget.rtlOpening
? Alignment.centerLeft
: Alignment.centerRight,
child: RepaintBoundary(
child: widget.drawer,
child: SlideTransition(
position: _drawerSlideAnimation,
child: FractionallySizedBox(
widthFactor: widget.openRatio,
child: ScaleTransition(
scale: _drawerScaleAnimation,
alignment: widget.rtlOpening
? Alignment.centerLeft
: Alignment.centerRight,
child: RepaintBoundary(
child: widget.drawer,
),
),
),
),
Expand Down Expand Up @@ -232,6 +242,11 @@ class _AdvancedDrawerState extends State<AdvancedDrawer>
end: 1.0,
).animate(parentAnimation);

_drawerSlideAnimation = Tween<Offset>(
begin: Offset(-widget.drawerSlideRatio, 0),
end: Offset.zero,
).animate(parentAnimation);

_childSlideAnimation = Tween<Offset>(
begin: Offset.zero,
end: Offset(widget.openRatio, 0),
Expand Down

0 comments on commit 00442c7

Please sign in to comment.